From 3aab1ff2ac8fc3ecb411933d2bcd65a51ea22716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Fri, 9 Sep 2022 11:16:36 +0200 Subject: [PATCH] feat: predam schema: enable copy icon for basins (except upstream/downstream) refs #522 --- .../pb-schema/pb-schema.component.ts | 15 +++++++++++---- src/app/services/prebarrage.service.ts | 19 ++++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 4f056bec4..2cf618100 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -476,14 +476,21 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } public get enableCopyButton() { - return this.predamService.isWallSelected(); + // disable copy for upstream/downstream basins + return this._selectedItem !== this.predamService.upstreamBassin; } - /** Copies a wall */ + /** Copies a wall or a basin */ public onCopyClick() { - const wallCopy: PbCloison = this.predamService.copySelectedWall(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit); + let copy: PbCloison | PbBassin; + if (this._selectedItem instanceof PbCloison) { + copy = this.predamService.copySelectedWall(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit); + } + else { + copy = this.predamService.copySelectedBasin(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit); + } this.clearResults(); - this.refreshWithSelection(wallCopy.uid); + this.refreshWithSelection(copy.uid); this.calculatorComponent.showPBInputData = true; } diff --git a/src/app/services/prebarrage.service.ts b/src/app/services/prebarrage.service.ts index bc5c8ebfe..41672a034 100644 --- a/src/app/services/prebarrage.service.ts +++ b/src/app/services/prebarrage.service.ts @@ -80,6 +80,14 @@ export class PrebarrageService { return newBasin; } + public copySelectedBasin(emptyFields: boolean): PbBassin { + const basin = this._selectedNub as PbBassin; + const basinCopy = new PbBassin(new PbBassinParams(20, 99, emptyFields)); + basinCopy.loadObjectRepresentation(basin.objectRepresentation()); + this._model.addChild(basinCopy); + return basinCopy; + } + public get hasBasins(): boolean { return this._model.bassins.length > 0; } @@ -140,8 +148,8 @@ export class PrebarrageService { private moveBasinDown(uid: string) { this._model.moveBasin(uid, this._model.findBasinPosition(uid) + 1); } - - public moveSelectedBasinDown(){ + + public moveSelectedBasinDown() { const uid = this._selectedNub.uid; this.moveBasinDown(uid); } @@ -199,11 +207,4 @@ export class PrebarrageService { return this.model.findChild(itemId); } } - - /** - * @returns true if selected nub is a wall - */ - public isWallSelected(): boolean { - return (this._selectedNub !== undefined && this._selectedNub instanceof PbCloison); - } } -- GitLab