mirror of https://gitee.com/cf-fz/WebCAD.git
parent
f95e0ff9fa
commit
5d2456a98e
@ -0,0 +1,95 @@
|
||||
import { Button, Card, Classes, Popover, Position, Radio, RadioGroup, Intent } from '@blueprintjs/core';
|
||||
import { observable } from 'mobx';
|
||||
import { observer } from 'mobx-react';
|
||||
import * as React from 'react';
|
||||
import { DrillStore } from '../../Store/DrillStore';
|
||||
|
||||
@observer
|
||||
export class DrillTypeCom extends React.Component<{ store: DrillStore }, { typeName: string }>
|
||||
{
|
||||
constructor(props)
|
||||
{
|
||||
super(props);
|
||||
this.state = {
|
||||
typeName: ""
|
||||
}
|
||||
}
|
||||
private addDrillType = () =>
|
||||
{
|
||||
this.props.store.AddNewDrillType(this.state.typeName);
|
||||
this.props.store.type = this.state.typeName;
|
||||
this.handleUpdate();
|
||||
}
|
||||
private handleOnChange = (e) =>
|
||||
{
|
||||
const store = this.props.store;
|
||||
store.type = e.currentTarget.value;
|
||||
this.handleUpdate();
|
||||
}
|
||||
private handleDelete = () =>
|
||||
{
|
||||
const store = this.props.store;
|
||||
store.drillConfig.delete(store.type);
|
||||
let types = [...store.drillConfig.keys()];
|
||||
if (types.length > 0)
|
||||
{
|
||||
store.type = types[0];
|
||||
this.handleUpdate();
|
||||
}
|
||||
}
|
||||
private handleUpdate = () =>
|
||||
{
|
||||
const store = this.props.store;
|
||||
observable(store.rules).replace(store.drillConfig.get(store.type));
|
||||
store.ChangeRules(0);
|
||||
}
|
||||
render()
|
||||
{
|
||||
const store = this.props.store;
|
||||
|
||||
return (
|
||||
<div className="flex drill-type">
|
||||
<RadioGroup
|
||||
inline={true}
|
||||
selectedValue={store.type}
|
||||
onChange={this.handleOnChange}
|
||||
>
|
||||
{
|
||||
[...store.drillConfig.keys()].map(type => <Radio label={type} value={type} />)
|
||||
}
|
||||
</RadioGroup>
|
||||
<div>
|
||||
<Popover
|
||||
position={Position.LEFT}
|
||||
onClosed={() => this.setState({ typeName: "" })}
|
||||
content={
|
||||
<Card>
|
||||
<input type="text"
|
||||
className={Classes.INPUT}
|
||||
value={this.state.typeName}
|
||||
onChange={e => this.setState({ typeName: e.target.value })}
|
||||
/>
|
||||
<Button
|
||||
text="确定"
|
||||
className={Classes.POPOVER_DISMISS}
|
||||
style={{ marginLeft: 20 }}
|
||||
onClick={this.addDrillType}
|
||||
/>
|
||||
</Card>
|
||||
}
|
||||
target={<Button
|
||||
text="添加类型"
|
||||
intent={Intent.PRIMARY}
|
||||
/>}
|
||||
/>
|
||||
<Button
|
||||
text="删除选中类型"
|
||||
intent={Intent.DANGER}
|
||||
onClick={this.handleDelete}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,161 +0,0 @@
|
||||
import { Button, Classes, Intent, Popover } from '@blueprintjs/core';
|
||||
import { observable } from 'mobx';
|
||||
import { observer } from 'mobx-react';
|
||||
import * as React from 'react';
|
||||
import { Matrix4, Vector3 } from 'three';
|
||||
import { app } from '../../../ApplicationServices/Application';
|
||||
import { Board } from '../../../DatabaseServices/Board';
|
||||
import { Curve } from '../../../DatabaseServices/Curve';
|
||||
import { Text } from '../../../DatabaseServices/Text/Text';
|
||||
import { JigUtils } from '../../../Editor/JigUtils';
|
||||
import { calcEdgeSealing, paragraphCulist } from '../../../GraphicsSystem/CalcEdgeSealing';
|
||||
import { MoveMatrix } from '../../../Geometry/GeUtils';
|
||||
|
||||
@observer
|
||||
export class EdgeSealingComponent extends React.Component<{ br: Board }, {}>
|
||||
{
|
||||
private ulList: HTMLUListElement;
|
||||
@observable private cuList: Curve[] = [];
|
||||
constructor(props)
|
||||
{
|
||||
super(props);
|
||||
}
|
||||
private EditorEdgeSealing = () =>
|
||||
{
|
||||
let br = this.props.br;
|
||||
let cus = br.ContourCurve.Explode() as Curve[];
|
||||
|
||||
//曲线分段
|
||||
paragraphCulist(cus);
|
||||
//替换曲线列表
|
||||
observable(this.cuList).replace(cus);
|
||||
|
||||
app.m_Viewer.m_CameraCtrl.LookAt(br.Normal.negate());
|
||||
app.m_Editor.UCSMatrix = new Matrix4().extractRotation(br.OCS);
|
||||
app.m_Editor.UpdateScreen();
|
||||
|
||||
JigUtils.Destroy();
|
||||
for (let i = 0; i < this.cuList.length; i++)
|
||||
{
|
||||
let cu = this.cuList[i];
|
||||
let p = cu.GetPointAtParam(cu.EndParam / 2);
|
||||
JigUtils.Draw(new Text(p, (i + 1).toString())
|
||||
.ApplyMatrix(MoveMatrix(new Vector3(0, 0, br.Thickness)))
|
||||
.ApplyMatrix(br.OCS));
|
||||
//显示对应设置的边
|
||||
let refCu = cu.Clone();
|
||||
refCu.ColorIndex = i + 1
|
||||
JigUtils.Draw(refCu.ApplyMatrix(br.OCS));
|
||||
}
|
||||
}
|
||||
|
||||
private CalcEdgeSealing = () =>
|
||||
{
|
||||
let originCurve = this.props.br.ContourCurve;
|
||||
let dir = Math.sign(originCurve.Area2) * -1;
|
||||
let infoEls = this.ulList.querySelectorAll('li input');
|
||||
let edgeSealingNum: number[] = [];
|
||||
let highSeal = this.props.br.BoardProcessOption.highSealed;
|
||||
highSeal.length = 0;
|
||||
infoEls.forEach(el =>
|
||||
{
|
||||
let size = parseFloat((el as HTMLInputElement).value);
|
||||
highSeal.push({
|
||||
size
|
||||
})
|
||||
edgeSealingNum.push(size * dir);
|
||||
});
|
||||
|
||||
let calcCus = this.cuList;
|
||||
let offsetCus: Curve[] = [];
|
||||
|
||||
for (let i = 0; i < calcCus.length; i++)
|
||||
{
|
||||
let cu = calcCus[i];
|
||||
offsetCus.push(...cu.GetOffsetCurves(edgeSealingNum[i]));
|
||||
}
|
||||
calcEdgeSealing(offsetCus);
|
||||
this.ShowSealingResult(offsetCus);
|
||||
}
|
||||
private ShowSealingResult = (offsetCus: Curve[]) =>
|
||||
{
|
||||
offsetCus.forEach((cu, i) =>
|
||||
{
|
||||
cu.ApplyMatrix(MoveMatrix(new Vector3(0, 0, this.props.br.Thickness)))
|
||||
.ApplyMatrix(this.props.br.OCS);
|
||||
JigUtils.Draw(cu);
|
||||
})
|
||||
app.m_Editor.UpdateScreen();
|
||||
}
|
||||
render()
|
||||
{
|
||||
let highSeal = this.props.br.BoardProcessOption.highSealed;
|
||||
//兼容以前没有这个属性的版本
|
||||
if (!highSeal)
|
||||
{
|
||||
this.props.br.BoardProcessOption.highSealed = [];
|
||||
highSeal = [];
|
||||
}
|
||||
return (
|
||||
<Popover
|
||||
usePortal={false}
|
||||
modifiers={{
|
||||
arrow: { enabled: false },
|
||||
flip: { enabled: true },
|
||||
keepTogether: { enabled: true },
|
||||
preventOverflow: { enabled: true, boundariesElement: "scrollParent" }
|
||||
}}
|
||||
content={
|
||||
<div tabIndex={-1} className={Classes.CARD}>
|
||||
<h6 className={Classes.HEADING}>封边编辑</h6>
|
||||
<ul
|
||||
className={Classes.LIST_UNSTYLED}
|
||||
ref={el => this.ulList = el}
|
||||
>
|
||||
{
|
||||
this.cuList.map((cu, i) =>
|
||||
{
|
||||
let defaultValue = "1.0";
|
||||
if (highSeal.length > 0)
|
||||
defaultValue = highSeal[i] ? highSeal[i].size.toString() : "1";
|
||||
return (
|
||||
<li>
|
||||
<label className="bp3-label bp3-inline .modifier">
|
||||
{"封边(" + (i + 1).toString() + ")"}
|
||||
<input
|
||||
defaultValue={defaultValue}
|
||||
className="bp3-input"
|
||||
placeholder="输入封边大小"
|
||||
dir="auto" />
|
||||
</label>
|
||||
</li>
|
||||
)
|
||||
})
|
||||
}
|
||||
</ul>
|
||||
<div style={{ display: "flex", justifyContent: "flex-end", marginTop: 15 }}>
|
||||
<Button
|
||||
onClick={this.CalcEdgeSealing}
|
||||
text="确定"
|
||||
className={Classes.POPOVER_DISMISS}
|
||||
intent={Intent.SUCCESS}
|
||||
style={{ marginRight: 10 }} />
|
||||
<Button
|
||||
text="取消"
|
||||
onClick={() => JigUtils.Destroy()}
|
||||
intent={Intent.DANGER}
|
||||
className={Classes.POPOVER_DISMISS} />
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
target={
|
||||
<Button
|
||||
onClick={this.EditorEdgeSealing}
|
||||
text="高级编辑"
|
||||
intent="success"
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
import { Button, Classes, HTMLSelect, Intent, Label } from '@blueprintjs/core';
|
||||
import { toJS } from 'mobx';
|
||||
import { inject, observer } from 'mobx-react';
|
||||
import * as React from 'react';
|
||||
import { ColorMaterial } from '../../../Common/ColorPalette';
|
||||
import { userConfig } from '../../../Editor/UserConfig';
|
||||
import { IndexedDbStore, StoreName } from '../../../IndexedDb/IndexedDbStore';
|
||||
import { RightPanelStore } from '../../Store/RightPanelStore';
|
||||
import { RightTabId } from './RightPanel';
|
||||
|
||||
|
||||
@inject("store")
|
||||
@observer
|
||||
export class DrillingComponent extends React.Component<{ store?: RightPanelStore }>
|
||||
{
|
||||
private save = async () =>
|
||||
{
|
||||
const store = this.props.store;
|
||||
let dbstore = await IndexedDbStore.CADStore();
|
||||
let drillData = await dbstore.Get(StoreName.ConfigData, RightTabId.Drill) as string[];
|
||||
if (drillData)
|
||||
{
|
||||
drillData.length = 0;
|
||||
drillData.push(...toJS(store.drillDataList));
|
||||
}
|
||||
else
|
||||
drillData = toJS(store.drillDataList);
|
||||
dbstore.Put(StoreName.ConfigData, RightTabId.Drill, drillData);
|
||||
}
|
||||
render()
|
||||
{
|
||||
const store = this.props.store;
|
||||
const options = userConfig.drillConfigs ? [
|
||||
...userConfig.drillConfigs.keys(), "不排"
|
||||
] : [];
|
||||
const options2 = ["排", "不排"];
|
||||
return (
|
||||
<>
|
||||
<ul className={"modeling drilling " + Classes.LIST_UNSTYLED}>
|
||||
<li>
|
||||
<Label>颜色</Label>
|
||||
<Label>排钻类型</Label>
|
||||
</li>
|
||||
{
|
||||
store.drillDataList.map((d, i) =>
|
||||
{
|
||||
if (i >= 2)
|
||||
return (
|
||||
<li>
|
||||
<span style={{
|
||||
background: ColorMaterial.GetColor(i - 1).getStyle(), width: "50%"
|
||||
}} className={Classes.INPUT}>{i - 1}</span>
|
||||
<HTMLSelect
|
||||
options={options}
|
||||
value={d}
|
||||
onChange={e =>
|
||||
{
|
||||
store.drillDataList[i] = e.target.value;
|
||||
}}
|
||||
/>
|
||||
</li>
|
||||
)
|
||||
})
|
||||
}
|
||||
</ul>
|
||||
<ul className={"modeling drilling " + Classes.LIST_UNSTYLED}>
|
||||
{
|
||||
store.drillDataList.length > 2 && <>
|
||||
<li>
|
||||
<span style={{ width: "50%" }} className={Classes.INPUT}>正面</span>
|
||||
<HTMLSelect
|
||||
options={options2}
|
||||
value={store.drillDataList[0]}
|
||||
onChange={e =>
|
||||
{
|
||||
store.drillDataList[0] = e.target.value;
|
||||
}}
|
||||
/>
|
||||
</li>
|
||||
<li>
|
||||
<span style={{ width: "50%" }} className={Classes.INPUT}>反面</span>
|
||||
<HTMLSelect
|
||||
options={options2}
|
||||
value={store.drillDataList[1]}
|
||||
onChange={e =>
|
||||
{
|
||||
store.drillDataList[1] = e.target.value;
|
||||
}}
|
||||
/>
|
||||
</li>
|
||||
</>
|
||||
}
|
||||
</ul>
|
||||
<div className="flex-arround">
|
||||
<Button text="确定" intent={Intent.SUCCESS} onClick={() => store.WriteDrillData()}
|
||||
/>
|
||||
<Button text="保存" intent={Intent.SUCCESS} onClick={this.save}
|
||||
/>
|
||||
<Button text="退出" intent={Intent.DANGER} onClick={() => store.ExitEditor()}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
import { Button, Classes, Intent, Label } from '@blueprintjs/core';
|
||||
import { toJS } from 'mobx';
|
||||
import { inject, observer } from 'mobx-react';
|
||||
import * as React from 'react';
|
||||
import { ColorMaterial } from '../../../Common/ColorPalette';
|
||||
import { IndexedDbStore, StoreName } from '../../../IndexedDb/IndexedDbStore';
|
||||
import { RightPanelStore } from '../../Store/RightPanelStore';
|
||||
import { RightTabId } from './RightPanel';
|
||||
|
||||
|
||||
@inject("store")
|
||||
@observer
|
||||
export class SealingComponent extends React.Component<{ store?: RightPanelStore }>
|
||||
{
|
||||
private addColor = () =>
|
||||
{
|
||||
this.props.store.highSizes.push("1");
|
||||
}
|
||||
private save = async () =>
|
||||
{
|
||||
const store = this.props.store;
|
||||
let dbstore = await IndexedDbStore.CADStore();
|
||||
let highSizes = await dbstore.Get(StoreName.ConfigData, RightTabId.Seal) as string[];
|
||||
if (highSizes)
|
||||
{
|
||||
highSizes.length = 0;
|
||||
highSizes.push(...toJS(store.highSizes));
|
||||
}
|
||||
else
|
||||
highSizes = toJS(store.highSizes);
|
||||
dbstore.Put(StoreName.ConfigData, RightTabId.Seal, highSizes);
|
||||
}
|
||||
render()
|
||||
{
|
||||
const store = this.props.store;
|
||||
|
||||
return (
|
||||
<>
|
||||
<ul className={"modeling " + Classes.LIST_UNSTYLED}>
|
||||
<li>
|
||||
<Label>颜色</Label>
|
||||
<Label>大小</Label>
|
||||
</li>
|
||||
{
|
||||
store.highSizes.map((v, i) =>
|
||||
{
|
||||
return (
|
||||
<li>
|
||||
<span
|
||||
className={Classes.INPUT}
|
||||
style={{
|
||||
background: ColorMaterial.GetColor(i + 1).getStyle(),
|
||||
width: "50%"
|
||||
}}
|
||||
>{i + 1}</span>
|
||||
<input
|
||||
style={{ width: "50%" }}
|
||||
tabIndex={1}
|
||||
value={v}
|
||||
onFocus={e =>
|
||||
{
|
||||
e.target.setSelectionRange(0, e.target.value.length);
|
||||
}}
|
||||
className={Classes.INPUT}
|
||||
onChange={(e) =>
|
||||
{
|
||||
store.highSizes[i] = e.target.value;
|
||||
}}
|
||||
onBlur={e =>
|
||||
{
|
||||
let val = parseFloat(e.target.value);
|
||||
if (isNaN(val))
|
||||
store.highSizes[i] = "0";
|
||||
}}
|
||||
/>
|
||||
</li>
|
||||
)
|
||||
})
|
||||
}
|
||||
</ul>
|
||||
<div className="flex-arround">
|
||||
<Button text="写入" intent={Intent.SUCCESS}
|
||||
onClick={() => store.WriteSealingData()} />
|
||||
<Button text="保存" intent={Intent.SUCCESS}
|
||||
onClick={this.save} />
|
||||
<Button text="退出" intent={Intent.DANGER}
|
||||
onClick={() => store.ExitEditor()} />
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
import { Singleton } from "../../Common/Singleton";
|
||||
import { observable } from "mobx";
|
||||
import { AppToaster } from "../Components/Toaster";
|
||||
import { IndexedDbStore, StoreName } from "../../IndexedDb/IndexedDbStore";
|
||||
import { IConfigOption } from "../Components/Board/UserConfig";
|
||||
import { IConfigStore } from "./BoardStore";
|
||||
import { BoardModalType } from "../Components/Board/BoardModal";
|
||||
import { arrayLast } from "../../Common/ArrayExt";
|
||||
import { userConfig } from "../../Editor/UserConfig";
|
||||
|
||||
export class UserConfigStore extends Singleton
|
||||
{
|
||||
@observable configName = "默认";
|
||||
@observable configs: Map<string, IConfigOption> = new Map();
|
||||
async GetConfig(type: BoardModalType): Promise<IConfigOption | null>
|
||||
{
|
||||
let dbstore = await IndexedDbStore.CADStore();
|
||||
let configs = await dbstore.Get(StoreName.ConfigData, type);
|
||||
if (configs)
|
||||
{
|
||||
let confNames = [...configs.keys()];
|
||||
let curName = localStorage.getItem("configName");
|
||||
if (!curName)
|
||||
curName = arrayLast(confNames);
|
||||
return configs.get(curName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
async SaveConfig(type: BoardModalType, store: IConfigStore, isInit: boolean = false)
|
||||
{
|
||||
let name = this.configName;
|
||||
if (name === "")
|
||||
{
|
||||
AppToaster.show({
|
||||
message: "请输入名称",
|
||||
timeout: 1000
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let dbstore = await IndexedDbStore.CADStore();
|
||||
|
||||
//新的配置
|
||||
let newConfig: IConfigOption = store.SaveConfig();
|
||||
|
||||
//获取数据库中对应板类型的配置
|
||||
let brDataMap = (await dbstore.Get(StoreName.ConfigData, type) || new Map()) as Map<string, IConfigOption>;
|
||||
|
||||
// 配置添加到数据库
|
||||
brDataMap.set(name, newConfig);
|
||||
|
||||
dbstore.Put(StoreName.ConfigData, type, brDataMap);
|
||||
observable(this.configs).replace(brDataMap);
|
||||
AppToaster.show({
|
||||
message: isInit ? "初始化配置成功" : "配置保存成功",
|
||||
timeout: 1000
|
||||
});
|
||||
localStorage.setItem("configName", name);
|
||||
if (type === BoardModalType.Dr)
|
||||
userConfig.drillConfigs = newConfig.ruleMap;
|
||||
}
|
||||
//删除配置
|
||||
async DeleteConfig(type: BoardModalType, store: IConfigStore)
|
||||
{
|
||||
// 删除视图中的对应项
|
||||
let currentName = this.configName;
|
||||
if (currentName === "默认")
|
||||
{
|
||||
AppToaster.show({
|
||||
message: "默认配置不允许删除",
|
||||
timeout: 1000
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.configs.delete(currentName);
|
||||
|
||||
//删除数据库中的对应项
|
||||
let dbstore = await IndexedDbStore.CADStore();
|
||||
let brDataMap = await dbstore.Get(StoreName.ConfigData, type) as Map<string, IConfigOption>;
|
||||
brDataMap.delete(currentName);
|
||||
dbstore.Put(StoreName.ConfigData, type, brDataMap);
|
||||
|
||||
//切换到第一项
|
||||
let confNames = Array.from(brDataMap.keys());
|
||||
let newName = confNames.length > 0 ? confNames[0] : "";
|
||||
this.configName = newName;
|
||||
await this.UpdateBoardOption(newName, type, store);
|
||||
localStorage.setItem("configName", newName);
|
||||
|
||||
if (type === BoardModalType.Dr)
|
||||
userConfig.drillConfigs = brDataMap.get(newName).ruleMap;
|
||||
}
|
||||
//更新配置
|
||||
UpdateBoardOption = async (k: string, type: BoardModalType, store: IConfigStore) =>
|
||||
{
|
||||
this.configName = k;
|
||||
let dbstore = await IndexedDbStore.CADStore();
|
||||
let brDataMap = await dbstore.Get(StoreName.ConfigData, type) as Map<string, IConfigOption>;
|
||||
let conf = brDataMap.get(k);
|
||||
if (brDataMap && conf)
|
||||
{
|
||||
store.UpdateOption(conf);
|
||||
localStorage.setItem("configName", k);
|
||||
if (type === BoardModalType.Dr)
|
||||
userConfig.drillConfigs = conf.ruleMap;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const userConfigStore = UserConfigStore.GetInstance() as UserConfigStore;
|
Loading…
Reference in new issue