diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 4f056bec407f10653660adeed2b37c1617d83d73..2cf618100ec5a19b326b1568f0110291e8b13ab5 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 bc5c8ebfe037c7ed885492ec46e9ad16fd0936fb..41672a034bfd851329911e9af71f26cf492cc79e 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); - } }