Skip to content
Snippets Groups Projects
Commit 255ffdf1 authored by François Grand's avatar François Grand
Browse files

fix: predam: wrong basin copied when copying from icon in basin list

refs #522
parent 21ec7e6e
No related branches found
No related tags found
1 merge request!166Resolve "Prébarrages: Regroupement de la saisie des bassins"
Pipeline #139827 passed
......@@ -29,7 +29,8 @@ export class BasinFieldsetContainerComponent extends FieldsetContainerComponent
}
protected addSubNub(after: FieldSet, clone?: boolean): void {
this.predamService.copySelectedBasin(ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
const fsIndex = this._container.kidIndex(after);
this.predamService.copyBasinByIndex(fsIndex, ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit);
}
public onRemoveFieldset(fs: FieldSet) {
......
......@@ -65,18 +65,8 @@ export class PrebarrageService {
* @param bi basin index
*/
public deleteBasinByIndex(bi: number, emptyFields: boolean) {
let nthBasin: number = 0;
let i: number = 0;
for (const kid of this._model.children) {
if (kid instanceof PbBassin) {
if (nthBasin == bi) {
this.deleteByIndex(i, emptyFields);
return;
}
nthBasin++;
}
i++;
}
const i = this.nthBasinIndex(bi);
this.deleteByIndex(i, emptyFields);
}
private deleteByIndex(i: number, emptyFields: boolean) {
......@@ -100,6 +90,26 @@ export class PrebarrageService {
);
}
/**
* compute index of nth basin
* @param bi nth basin
* @returns index in child list
*/
private nthBasinIndex(bi): number {
let nth: number = 0;
let res: number = 0;
for (const kid of this._model.children) {
if (kid instanceof PbBassin) {
if (nth == bi) {
return res;
}
nth++;
}
res++;
}
return -1;
}
private copyWall(wall: PbCloison, emptyFields: boolean): PbCloison {
const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval, undefined, emptyFields);
wallCopy.loadObjectRepresentation(wall.objectRepresentation());
......@@ -132,7 +142,19 @@ export class PrebarrageService {
}
public copySelectedBasin(emptyFields: boolean) {
const basin = this._selectedNub as PbBassin;
this.copyBasin(this._selectedNub as PbBassin, emptyFields);
}
/**
* copy nth basin
* @param bi basin index
*/
public copyBasinByIndex(bi: number, emptyFields: boolean) {
const i = this.nthBasinIndex(bi);
this.copyBasin(this._model.children[i] as PbBassin, emptyFields);
}
private copyBasin(basin: PbBassin, emptyFields: boolean) {
const basinCopy = new PbBassin(new PbBassinParams(20, 99, emptyFields));
basinCopy.loadObjectRepresentation(basin.objectRepresentation());
this._model.addChild(basinCopy);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment