!324 背板及其他板件自动切割

Merge pull request !324 from 肖诗雅/autoCutting
pull/324/MERGE
肖诗雅 5 years ago committed by ChenX
parent 6f9a3f9c45
commit 4443a7a9f7

@ -0,0 +1,34 @@
import { app } from "../../ApplicationServices/Application";
import { Board } from "../../DatabaseServices/Board";
import { userConfig } from "../../Editor/UserConfig";
import { NonAssociativeCutting } from "./NonAssociativeCutting";
export class AutoCuttingReactor
{
Enable = true;
constructor()
{
this.Enable = userConfig.openAutoCuttingReactor;
app.m_CommandReactor.OnCommandEnd((cmdName, changeObjects, createObjects) =>
{
if (!this.Enable) return;
let brs = createObjects.filter(o => o instanceof Board) as Board[];
if (brs.length > 0)
this.StartReactor(brs);
});
}
StartReactor(ents: Board[])
{
let nc = new NonAssociativeCutting();
let brs: Board[] = [];
for (let ent of app.m_Viewer.VisibleEntitys)
{
if (ent instanceof Board && !ents.includes(ent))
brs.push(ent);
}
for (let br of brs)
nc.CuttingBoard(br, ents);
}
}

@ -49,9 +49,9 @@ export class NonAssociativeCutting implements Command
this.CuttingBoard(br, brs2);
}
async CuttingBoard(orgBoard: Board, cutBoards: Board[])
async CuttingBoard(orgBoard: Board, knifBoards: Board[])
{
for (let br of cutBoards)
for (let br of knifBoards)
{
let gs = orgBoard.ConverToLocalGroove(br.Clone());
for (let g of gs)

@ -1,6 +1,5 @@
import { app } from "../../ApplicationServices/Application";
import { GetEntity } from "../../Common/Utils";
import { GangDrill } from "../../DatabaseServices/3DSolid/GangDrill";
import { Board } from "../../DatabaseServices/Board";
import { userConfig } from "../../Editor/UserConfig";
import { DrawDrillingTool } from "./DrawDrillingTool";
@ -10,15 +9,14 @@ const ForbidReactorCmd = ['DELETEDRILL', 'PZ', 'ENT'];
export class DrillingReactor
{
Enable = true;
constructor()
{
if (userConfig.openDrillingReactor)
this.Watch();
}
Watch()
{
this.Enable = userConfig.openDrillingReactor;
app.m_CommandReactor.OnCommandEnd((cmdName: string, changeObjects, createObjects) =>
{
if (!this.Enable) return;
if (ForbidReactorCmd.includes(cmdName))
return;
let brs = [...new Set([...createObjects, ...changeObjects])]
@ -69,8 +67,4 @@ export class DrillingReactor
}
}
}
Cancel()
{
app.m_CommandReactor.Destory();
}
}

@ -19,6 +19,7 @@ import { CommandReactor } from '../Reactor/CommandReactor';
import { appUi } from '../UI/Layout/ApplicationLayout';
import { DownPanelStore } from '../UI/Store/DownPanelStore';
import { HostApplicationServices } from './HostApplicationServices';
import { AutoCuttingReactor } from '../Add-on/BoardCutting/AutoCuttingReactor';
export let app: ApplicationService;
/**
@ -31,6 +32,7 @@ export class ApplicationService
m_Editor: Editor;
m_CommandReactor: CommandReactor;
_drillingReactor: DrillingReactor;
_autoCuttingReactor: AutoCuttingReactor;
constructor()
{
app = this;
@ -108,6 +110,7 @@ export class ApplicationService
});
this.m_CommandReactor = new CommandReactor(this);
this._autoCuttingReactor = new AutoCuttingReactor();
this._drillingReactor = new DrillingReactor();
window["app"] = this;

@ -13,6 +13,7 @@ export class UserConfig
isContinuousDraw = false; //是否连续绘制层板立板背板...
@observable _drillConfigs: Map<string, DrillingOption[]> = new Map();
@observable openDrillingReactor = true;
@observable openAutoCuttingReactor = true;
constructor()
{
this.Init();

@ -8,6 +8,8 @@ function isShowObject ( object ) {
THREE.OutlinePass = function ( resolution, scene, camera, selectedObjects ) {
this.renderObjects = [];
this.renderScene = scene;
this.renderCamera = camera;
this.selectedObjects = selectedObjects !== undefined ? selectedObjects : [];
@ -261,7 +263,7 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
},
render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
this.renderObjects.length = 0;
if ( this.selectedObjects.length > 0 ) {
this.oldClearColor.copy( renderer.getClearColor() );
@ -281,8 +283,12 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
this.renderScene.background = null;
// 1. Draw Non Selected objects in the depth buffer
this.renderScene.overrideMaterial = this.depthMaterial;
renderer.render( this.renderScene, this.renderCamera, this.renderTargetDepthBuffer, true );
this.renderScene.overrideMaterial = this.depthMaterial;
renderer.render(this.renderScene, this.renderCamera, this.renderTargetDepthBuffer, true);
//缓存renderObjects
let renderList = renderer.renderLists.get( this.renderScene, this.renderCamera );
this.renderObjects = [...renderList.transparent.map(o => o.object),...renderList.opaque.map(o => o.object)];
// Make selected objects visible
this.changeVisibilityOfSelectedObjects( true );

@ -297,13 +297,16 @@ export class Viewer
/**
* (Threejs).
* OutlinePass,,.
*/
get VisibleObjects(): Object3D[]
{
//@ts-ignore
let renderObjects: Object3D[] = this.m_OutlinePass.renderObjects;
if (renderObjects.length > 0)
return renderObjects;
let renderList = this.m_Render.renderLists.get(this.m_Scene, this.m_CameraCtrl.Camera);
return renderList.transparent.map(o => o.object)
.concat(renderList.opaque.map(o => o.object));
return [...renderList.transparent.map(o => o.object), ...renderList.opaque.map(o => o.object)];
}
get VisibleEntitys(): Entity[]

@ -38,10 +38,10 @@ export class CommandReactor
if (this._commandEndListeners.length === 0)
return;
this._changeObjects = this.app.m_Database.hm.ChangeObjects;
for (let listener of this._commandEndListeners)
{
//反应器可能相互影响,所以不缓存这个
this._changeObjects = this.app.m_Database.hm.ChangeObjects;
listener(this._cmdName, this._changeObjects, this._createObejcts);
}
});
@ -53,8 +53,4 @@ export class CommandReactor
{
this._commandEndListeners.push(listener);
}
Destory()
{
this._commandEndListeners.length = 0;
}
}

@ -14,15 +14,14 @@ export class ConfigCom extends React.Component<IConfigProps, {}> {
private toggleDrillingReactor = () =>
{
const userConfig = this.props.store;
userConfig.openDrillingReactor = !userConfig.openDrillingReactor
if (!userConfig.openDrillingReactor)
{
app._drillingReactor.Cancel();
}
else
{
app._drillingReactor.Watch();
}
userConfig.openDrillingReactor = !userConfig.openDrillingReactor;
app._drillingReactor.Enable = userConfig.openDrillingReactor;
}
private toggleAutoCuttingReactor = () =>
{
const userConfig = this.props.store;
userConfig.openAutoCuttingReactor = !userConfig.openAutoCuttingReactor;
app._autoCuttingReactor.Enable = userConfig.openAutoCuttingReactor;
}
public render()
{
@ -36,6 +35,12 @@ export class ConfigCom extends React.Component<IConfigProps, {}> {
checked={userConfig.openDrillingReactor}
onChange={this.toggleDrillingReactor}
/>
<H5></H5>
<Checkbox
label="自动切割"
checked={userConfig.openAutoCuttingReactor}
onChange={this.toggleAutoCuttingReactor}
/>
<H5></H5>
<Label className={Classes.INLINE}>
<span></span>

Loading…
Cancel
Save