import { CompBase } from "./base" import { HistoryController } from "./history"; export type TransferValue = { stageX: number; stageY: number; showOrthScale: boolean; toolbars: string[]; matrixInvert: string; relWidth: number; relHeight: number; showScaleBridge: boolean; showScaletop: boolean; showScalebottom: boolean; selected: string[]; } export class NodeTransfer extends CompBase { override onCreated() { this.compKey = "Transfer"; this.state.size = [750, 60]; } override init(): void { this._bounds.clear(); this.value.selected.forEach(id=>{ const obj = this.getObj(id); obj.getLocalBounds() this._bounds.addBounds(obj._bounds); }) const rect = this._bounds.getRectangle(); this.state.size[0] = rect.width; this.state.size[1] = rect.height; this.position = {x: rect.x, y: rect.y} as any; this.value.onSelectedChanged(()=>{ this.updateSeleted(); }) super.init(); this.updateMatrix(); } translate(x: number, y:number) { this.x += x; this.y += y; this.updateMatrix(); } rotate(r:number) { this.rotation = r; this.updateMatrix(); } updateSeleted() { const selected = this.value.selected; console.log("selected=>", selected); const parent = this.getObj(this.value.selected[0]).parent as CompBase; //获取父亲对象 const last = [] as string[]; parent.state.children.forEach(id=>{ if (selected.indexOf(id) == -1) last.push(id); }) parent.changeChildNodes(last, false); //更新当前内容 this.changeChildNodes(selected, true); } } export function createNodeTransfer(values: Partial, h: HistoryController) { const options = { stageX: 0, showScaletop: true, selected: [], showScalebottom: true, stageY: 0,relWidth:0, relHeight:0, showScaleBridge:true, matrixInvert:"matrix(1,0,0,1,0,0)", showOrthScale:false, toolbars:[], ...values}; const obj = new NodeTransfer(options) obj.init(); obj.setHistory(h); return obj; }