import {BehaviorService} from "../behavior/BehaviorService"; import {observable, map, action, transaction, autorun, autorunAsync} from "mobx/lib/mobx"; import {Unit, RectUnit, SizeUnit, SizeF} from "../../drawing/Unit"; import {SnapGridService} from "../behavior/SnapGridService"; import {ReportBandBase} from "../../items/band/ReportBandBase"; import {Report} from "../../items/Report"; import {SelectionService} from "../behavior/SelectionService"; import {ReportRootBehavior} from "../behavior/ReportRootBehavior"; import {Glyph} from "../behavior/Glyph"; import {ItemBodyGlyph} from "../behavior/ItemBodyGlyph"; import {Cursor} from "../../drawing/Cursor"; import {ItemSelectionType} from "../behavior/Enums"; import {Behavior} from "../behavior/Behavior"; import {ParentItemDesignerBase} from "./ParentItemDesignerBase"; import {DetailBand} from "../../items/band/DetailBand"; import {PageHeaderBand, PageFooterBand} from "../../items/band/PageBand"; import {ColumnHeaderBand, ColumnFooterBand} from "../../items/band/ColumnBand"; import {TitleBand} from "../../items/band/TitleBand"; import {OverLapService} from "../behavior/OverLapService"; import {RULE_WIDTH} from "../ui/ruler/consts"; import {autobind} from "core-decorators"; import {ReportItemBase} from "../../items/ReportItemBase"; import {ReportProperty, CommonProperty} from "../../items/properties/define"; import {DataTableEditService} from "../behavior/DataTableEditService"; import {SnapLine, SnapLineType, SnapLinePriority} from "../behavior/SnapLine"; import {DesignerHost} from "../DesignerHost"; const Konva = require("konva"); export enum AdornerLevels { SnapGrid = 0, Items = 1, // item ItemFrames = 2, // item 边框 Selection = 150, // 选中 RectSelection = 200, // 划选 EditingItem = 205, // 可编辑item DimensionLines = 250, // 坐标线 SnapLines = 300, // 对齐辅助线 } const ReportPadding = 50; const ReportRulerWidth = 0; export class ReportRootDesigner extends ParentItemDesignerBase { static Padding = Unit.pixel(ReportPadding); private _snapGridService: SnapGridService; private _snapGridSize: Unit; private _snapToGrid = true; private _snapToSnapLines = true; private _showDimensions = true; @observable private _report: Report; private _left:Unit; private _top:Unit; private _rulerWidth = ReportRulerWidth; @observable private _showSnapGrid = true; @observable private _zoom = 1.0; @observable private _viewPortScrollTop = 0; @observable private _viewPortScrollLeft = 0; /** * 报表设计视图大小,viewPortSize 永远 >= surfaceSize * @type {SizeF} * @private */ @observable private _viewPortSize = new SizeF(0, 0); /** * 报表设计器区的表面空间大小,也就是用户实际看到的大小而不是报表大小 * @type {SizeF} * @private */ @observable private _surfaceSize = new SizeF(0, 0); /** * 报表需要的最小空间大小,也就是应该容纳报表已有元素的最小空间大小要求 * @type {SizeF} * @private */ private _requiredMinSize = new SizeF(0, 0); @observable private _workSpaceSize = { width: 0, height: 0, }; @observable private _paperSize = { width: 0, height: 0, }; @observable private _bandsSumHeight = 0; @observable private _bandsSumWidth = 0; private _autonrunDisposer; get report():Report { return this._report; } get reportDesigner(): ReportRootDesigner { return this; } initialize(report: Report) { const savedReport = this._report; super.initialize(report); this._report = report; this._report.isUnbound = false; if (savedReport && savedReport !== report) { savedReport.dispose(); } this._left = new Unit(0); this._top = new Unit(0); this._paperSize.width = this._report.width.fPixels; this._paperSize.height = this._report.height.fPixels; this._workSpaceSize.width = this._report.width.fPixels + ReportRootDesigner.Padding.pixels * 2; this._workSpaceSize.height = this._report.height.fPixels + ReportRootDesigner.Padding.pixels * 2; if (! this._autonrunDisposer) { const selectionService = new SelectionService(this.host); this.host.addService(SelectionService, selectionService); this._snapGridSize = new Unit(0.1, Unit.defaultType); this._behaviorService = new BehaviorService(); this.host.addService(BehaviorService, this._behaviorService); this._snapGridService = new SnapGridService(this, this._behaviorService); this.host.addService(SnapGridService, this._snapGridService); const overLapService = new OverLapService(); this.host.addService(OverLapService, overLapService); const dataTableEditService = new DataTableEditService(); this.host.addService(DataTableEditService, dataTableEditService); this.recaculateViewSize(); this.report.on(Report.OnResizeChangeEventName, this.recaculateViewSize); this._autonrunDisposer = autorun(() => { const zoom = this.behaviorService.zoom; transaction(() => { let height = 0; let bandWidth = this.report.bandWidth.pixels / zoom; this.report.items.forEach(item => { const unit = item.getPropertyValue(CommonProperty.height) as Unit; height += unit.pixels; }); if (height !== this._bandsSumHeight || this._bandsSumWidth != bandWidth) { this._bandsSumHeight = height; this._bandsSumWidth = bandWidth; this.recaculateViewSize(); } }) }) } } get bandBottom(): number { return this._bandsSumHeight + this.report.topMargin.pixels; } get zoom(): number { return this._zoom; } set zoom(value: number) { this._zoom = value; } get showSnapGrid(): boolean { return this._showSnapGrid; } set showSnapGrid(value: boolean) { this._showSnapGrid = value; } @autobind private recaculateViewSize() { const zoom = this.behaviorService.zoom; const minSize = this.calculateAllowedShrinkSize(); minSize.width = minSize.width; minSize.height = minSize.height; const stageWidth = Math.max( this._surfaceSize.width - RULE_WIDTH, Math.max( minSize.width + this.report.rightMargin.pixels * zoom, this.report.width.pixels + (this.report.rightMargin.pixels + this.report.leftMargin.pixels) * zoom ) ); const stageHeight = Math.max( this._surfaceSize.height - RULE_WIDTH, (this._bandsSumHeight + this.report.topMargin.pixels + this.report.bottomMargin.pixels) * zoom // Math.max(this._bandsSumHeight + this.report.topMargin.pixels, this.report.height.toPixel()) ); this._requiredMinSize = new SizeF(minSize.width, minSize.height); if (this._viewPortSize.width !== stageWidth || this._viewPortSize.height !== stageHeight) { this._viewPortSize = new SizeF(stageWidth, stageHeight); } } get viewPortScrollTop(): number { return this._viewPortScrollTop; } set viewPortScrollTop(value: number) { this._viewPortScrollTop = value; } get viewPortScrollLeft(): number { return this._viewPortScrollLeft; } set viewPortScrollLeft(value: number) { this._viewPortScrollLeft = value; } get requiredMinSize(): SizeF { return this._requiredMinSize; } get viewPortSize(): SizeF { return this._viewPortSize; } get surfaceSize(): SizeF { return this._surfaceSize; } set surfaceSize(value: SizeF) { transaction(() => { this._surfaceSize = new SizeF(value.width, value.height); this.recaculateViewSize(); }); } updateMinBounds():boolean { return false; } get showDimensions():boolean { return this._showDimensions; } set showDimensions(value:boolean) { this._showDimensions = value; } get snapToSnapLines():boolean { return this._snapToSnapLines; } get snapToGrid():boolean { return this._snapToGrid; } set snapToGrid(value:boolean) { this._snapToGrid = value; } get behaviorService():BehaviorService { return this._behaviorService; } get snapGridSize():Unit { return this._snapGridSize; } get rulerWidth(): number { return this._rulerWidth; } getPaperSize(): {width: number, height: number} { return { width: this.report.width.pixels, height: this.report.height.pixels, }; } createDefaultBehavior():Behavior { return new ReportRootBehavior(this, this.host); } protected getDefaultItemBodyGlyph(): ItemBodyGlyph { return new ReportGlyph(this, Cursor.Default, this.defaultBehavior); } get bounds():RectUnit { return new RectUnit( this._left, this._top, Unit.pixel(this.viewPortSize.width / this.zoom), Unit.pixel(this.viewPortSize.height / this.zoom) ); } static getBandOrderd(report: Report): Array { const orderBands = []; let band = null; if ((band = report.items.find(item => item.constructor.name === TitleBand.name))) { orderBands.push(band); } if ((band = report.items.find(item => item.constructor.name === PageHeaderBand.name))) { orderBands.push(band); } if ((band = report.items.find(item => item.constructor.name === ColumnHeaderBand.name))) { orderBands.push(band); } // Group Band Header for (let group of report.groups) { if (group.groupHeader) { orderBands.push(group.groupHeader); } } // detail bands report.items.filter(item => item.constructor.name === DetailBand.name).forEach(band => orderBands.push(band)); // Group Band Footer for (let len = report.groups.length;len>0;len--){ if (report.groups[len-1].groupFooter) { orderBands.push(report.groups[len-1].groupFooter); } } if ((band = report.items.find(item => item.constructor.name === ColumnFooterBand.name))) { orderBands.push(band); } if ((band = report.items.find(item => item.constructor.name === PageFooterBand.name))) { orderBands.push(band); } return orderBands; } } export class ReportGlyph extends ItemBodyGlyph { render(parentNode) { } }