diff --git a/src/app/components/pab-table/pab-table.component.ts b/src/app/components/pab-table/pab-table.component.ts index 2981fb7035587b2a8a1910c9b336779b1fc4b51e..139505fd4c4beae323f554ae2109b979a636cc0c 100644 --- a/src/app/components/pab-table/pab-table.component.ts +++ b/src/app/components/pab-table/pab-table.component.ts @@ -12,7 +12,8 @@ import { Structure, ParallelStructure, ParamDefinition, - round + round, + CloisonAval } from "jalhyd"; import { sprintf } from "sprintf-js"; @@ -791,6 +792,28 @@ export class PabTableComponent implements AfterViewInit, OnInit { return ok; } + /** + * Returns true if there is at least one selected item, + * all selected items are devices, and belong to the same column + */ + private onlyDevicesOfTheSameColumnAreSelected() { + let ok = false; + let columnIndex: number; + if (this.selectedItems.length > 0) { + ok = true; + for (const s of this.selectedItems) { + if (s instanceof Structure) { + const ci = s.findPositionInParent(); + ok = ok && (columnIndex === undefined || columnIndex === ci); + columnIndex = ci; + } else { + ok = false; + } + } + } + return ok; + } + /** * Returns true if there is at least one selected item, * and all selected items are walls @@ -825,21 +848,22 @@ export class PabTableComponent implements AfterViewInit, OnInit { public get enableAddButton() { return ( - this.selectedItems.length === 1 - && this.selectedItem.parent // exclude downwall + this.onlyDevicesOfTheSameColumnAreSelected() + || ( + this.selectedItems.length === 1 + && ! (this.selectedItem instanceof CloisonAval) // exclude downwall + ) ); } public get enableCopyButton() { - return ( - this.selectedItems.length === 1 - && this.selectedItem.parent // exclude downwall - ); + return this.enableAddButton; } public get enableUpButton() { return ( this.selectedItems.length === 1 + && ! (this.selectedItem instanceof CloisonAval) // exclude downwall && this.selectedItem.parent && this.selectedItem.findPositionInParent() !== 0 ); @@ -848,6 +872,7 @@ export class PabTableComponent implements AfterViewInit, OnInit { public get enableDownButton() { return ( this.selectedItems.length === 1 + && ! (this.selectedItem instanceof CloisonAval) // exclude downwall && this.selectedItem.parent && this.selectedItem.findPositionInParent() < (this.selectedItem.parent.getChildren().length - 1) ); @@ -856,6 +881,7 @@ export class PabTableComponent implements AfterViewInit, OnInit { public get enableRemoveButton() { return ( this.selectedItems.length === 1 + && ! (this.selectedItem instanceof CloisonAval) // exclude downwall && this.selectedItem.parent && this.selectedItem.parent.getChildren().length > 1 ); @@ -877,32 +903,34 @@ export class PabTableComponent implements AfterViewInit, OnInit { public onAddClick() { // add default item for (let i = 0; i < this.childrenToAdd; i++) { - if (this.selectedItem instanceof Structure) { - // add new default device for wall parent - const newDevice = Session.getInstance().createNub( - new Props({ - calcType: CalculatorType.Structure, - loiDebit: (this.selectedItem.parent as ParallelStructure).getDefaultLoiDebit() - }) - ); - this.selectedItem.parent.addChild(newDevice, this.selectedItem.findPositionInParent()); + for (const si of this.selectedItems) { + if (si instanceof Structure) { + // add new default device for wall parent + const newDevice = Session.getInstance().createNub( + new Props({ + calcType: CalculatorType.Structure, + loiDebit: (si.parent as ParallelStructure).getDefaultLoiDebit() + }) + ); + si.parent.addChild(newDevice, si.findPositionInParent()); - } else { - // add new default wall for PAB parent - const newWall = Session.getInstance().createNub( - new Props({ - calcType: CalculatorType.Cloisons - }) - ); - // add new default device for new wall - const newDevice = Session.getInstance().createNub( - new Props({ - calcType: CalculatorType.Structure, - loiDebit: (newWall as ParallelStructure).getDefaultLoiDebit() - }) - ); - newWall.addChild(newDevice); - this.model.addChild(newWall, this.selectedItem.findPositionInParent()); + } else { + // add new default wall for PAB parent + const newWall = Session.getInstance().createNub( + new Props({ + calcType: CalculatorType.Cloisons + }) + ); + // add new default device for new wall + const newDevice = Session.getInstance().createNub( + new Props({ + calcType: CalculatorType.Structure, + loiDebit: (newWall as ParallelStructure).getDefaultLoiDebit() + }) + ); + newWall.addChild(newDevice); + this.model.addChild(newWall, si.findPositionInParent()); + } } } this.refresh(); @@ -910,17 +938,18 @@ export class PabTableComponent implements AfterViewInit, OnInit { // notify const pos = this.selectedItem.findPositionInParent() + 1; let msg: string; - if (this.childrenToAdd === 1) { + if (this.childrenToAdd === 1 && this.selectedItems.length === 1) { if (this.selectedItem instanceof Structure) { - msg = sprintf(this.i18nService.localizeText("INFO_DEVICE_ADDED"), pos); + msg = this.i18nService.localizeText("INFO_DEVICE_ADDED"); } else { - msg = sprintf(this.i18nService.localizeText("INFO_WALL_ADDED"), pos); + msg = this.i18nService.localizeText("INFO_WALL_ADDED"); } } else { + const size = (this.childrenToAdd * this.selectedItems.length); if (this.selectedItem instanceof Structure) { - msg = sprintf(this.i18nService.localizeText("INFO_DEVICE_ADDED_N_TIMES"), this.childrenToAdd); + msg = sprintf(this.i18nService.localizeText("INFO_DEVICE_ADDED_N_TIMES"), size); } else { - msg = sprintf(this.i18nService.localizeText("INFO_WALL_ADDED_N_TIMES"), this.childrenToAdd); + msg = sprintf(this.i18nService.localizeText("INFO_WALL_ADDED_N_TIMES"), size); } } this.notifService.notify(msg); @@ -931,54 +960,57 @@ export class PabTableComponent implements AfterViewInit, OnInit { public onCopyClick() { // cloned selected item for (let i = 0; i < this.childrenToAdd; i++) { - const newChild = Session.getInstance().createNub( - this.selectedItem.properties.clone(), - this.selectedItem.parent - ); - // copy parameter values - for (const p of this.selectedItem.prms) { - newChild.getParameter(p.symbol).singleValue = p.singleValue; - } - // copy children - if (this.selectedItem instanceof ParallelStructure) { - for (const c of this.selectedItem.getChildren()) { - const newGrandChild = Session.getInstance().createNub( - c.properties.clone(), - newChild - ); - // copy children parameters values - for (const p of c.prms) { - newGrandChild.getParameter(p.symbol).singleValue = p.singleValue; + for (const si of this.selectedItems) { + const newChild = Session.getInstance().createNub( + si.properties.clone(), + si.parent + ); + // copy parameter values + for (const p of si.prms) { + newChild.getParameter(p.symbol).singleValue = p.singleValue; + } + // copy children + if (si instanceof ParallelStructure) { + for (const c of si.getChildren()) { + const newGrandChild = Session.getInstance().createNub( + c.properties.clone(), + newChild + ); + // copy children parameters values + for (const p of c.prms) { + newGrandChild.getParameter(p.symbol).singleValue = p.singleValue; + } + // add to parent + newChild.addChild( + newGrandChild, + c.findPositionInParent() + ); } - // add to parent - newChild.addChild( - newGrandChild, - c.findPositionInParent() - ); } + // add to parent + si.parent.addChild( + newChild, + si.findPositionInParent() + ); } - // add to parent - this.selectedItem.parent.addChild( - newChild, - this.selectedItem.findPositionInParent() - ); } this.refresh(); // notify const pos = this.selectedItem.findPositionInParent() + 1; let msg: string; - if (this.childrenToAdd === 1) { + if (this.childrenToAdd === 1 && this.selectedItems.length === 1) { if (this.selectedItem instanceof Structure) { msg = sprintf(this.i18nService.localizeText("INFO_DEVICE_COPIED"), pos); } else { msg = sprintf(this.i18nService.localizeText("INFO_WALL_COPIED"), pos); } } else { + const size = (this.childrenToAdd * this.selectedItems.length); if (this.selectedItem instanceof Structure) { - msg = sprintf(this.i18nService.localizeText("INFO_DEVICE_COPIED_N_TIMES"), pos, this.childrenToAdd); + msg = sprintf(this.i18nService.localizeText("INFO_DEVICE_COPIED_N_TIMES"), pos, size); } else { - msg = sprintf(this.i18nService.localizeText("INFO_WALL_COPIED_N_TIMES"), pos, this.childrenToAdd); + msg = sprintf(this.i18nService.localizeText("INFO_WALL_COPIED_N_TIMES"), pos, size); } } this.notifService.notify(msg);