diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index dc3d0900ac45821f76d76f09941e48008d3d8135..718ff08f5a873b395b553155be771e2e4b3d3a69 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -541,6 +541,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe * réception d'un événement de changement de valeur d'un input */ public onInputChange(event: any) { + // console.debug(`CalculatorComponent.onInputChange(${event?.symbol})`); this._formulaire.resetResults([], (event ? event.symbol : undefined)); } @@ -584,6 +585,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe /** réception d'un événement de clic sur un nœud du schéma de PréBarrage */ public onPBNodeSelected(event: any) { + // console.debug(`GenericCalculatorComponent.onPBNodeSelected(${event?.node?.uid})`); // show proper form (actually subform elements) or proper results, // depending on what was clicked (this._formulaire as FormulairePrebarrage).nodeSelected(event.node); diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 026f5e3ee862233e712ca42200a69f90e73b69dd..cdbe3fad0932b9ebd36b8fc3ad8c692c166d987a 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -298,6 +298,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } private selectNode(item: any) { + // console.debug(`PbSchemaComponent.selectNode(${item?.id})`); // highlight clicked element this.clearHighlightedItems(); item.classList.add("node-highlighted"); @@ -449,9 +450,9 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.model.addChild(new PbCloison(undefined, this._selectedItem.bassinAval)); } } - this.unselect(); - this.refresh(); this.clearResults(); + this.unselect(); + this.refreshWithSelection(); this.calculatorComponent.showPBInputData = true; } @@ -476,10 +477,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval); wallCopy.loadObjectRepresentation(wall.objectRepresentation()); this.model.addChild(wallCopy); - this.unselect(); - this.refresh(); - this.selectNodeOnSchema(wallCopy); this.clearResults(); + this.refreshWithSelection(wallCopy.uid); this.calculatorComponent.showPBInputData = true; } @@ -491,10 +490,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni public onAddBasinClick() { const newBasin = new PbBassin(new PbBassinParams(20, 99)); this.model.addChild(newBasin); - this.unselect(); - this.refresh(); - this.selectNodeOnSchema(newBasin); this.clearResults(); + this.refreshWithSelection(newBasin.uid); this.calculatorComponent.showPBInputData = true; } @@ -526,10 +523,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni result.down === 0 ? undefined : this.model.bassins[result.down - 1] ); this.model.addChild(wall); - this.unselect(); - this.refresh(); - this.selectNodeOnSchema(wall); this.clearResults(); + this.refreshWithSelection(wall.uid); this.calculatorComponent.showPBInputData = true; } }); @@ -552,10 +547,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.model.moveBasin(this._selectedItem.uid, this.model.findBasinPosition(this._selectedItem.uid) - 1); } const basin = this._selectedItem; - this.unselect(); - this.refresh(); - this.selectNodeOnSchema(basin); this.clearResults(); + this.refreshWithSelection(this._selectedItem.uid); this.calculatorComponent.showPBInputData = true; } @@ -576,10 +569,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.model.moveBasin(this._selectedItem.uid, this.model.findBasinPosition(this._selectedItem.uid) + 1); } const basin = this._selectedItem; - this.unselect(); - this.refresh(); - this.selectNodeOnSchema(basin); this.clearResults(); + this.refreshWithSelection(this._selectedItem.uid); this.calculatorComponent.showPBInputData = true; } @@ -659,6 +650,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } private unselect() { + // console.debug(`PbSchemaComponent.unselect()`); this._selectedItem = undefined; this.clearHighlightedItems(); this.nodeSelected.emit({}); // nothing selected @@ -667,7 +659,6 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni /** clear all PB form results whenever the basins / walls layout is changed */ private clearResults() { this.pbSchema.form.reset(); - this.refreshWithSelection(); } /** @@ -675,9 +666,9 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni * nub uid, else keeps previous selection */ private refreshWithSelection(uid ?: string) { + // console.debug(`PbSchemaComponent.refreshWithSelection(${uid})`); // remember previously selected node const selectedNodeUID = this._selectedItem?.uid; - this.unselect(); this.refresh(); // select a specific node on the schema if (uid !== undefined) { @@ -691,6 +682,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni // interface Observer public update(sender: IObservable, data: any) { + // console.debug(`PbSchemaComponent.update:`, data); if (sender instanceof PbSchema) { if (data.action === "refresh") { this.refreshWithSelection(data.value); diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index 54231bc1a3580b892b1b65c76fcbd18d1c5066a3..4e1811f5cdc6956496ec9c0226c6669c9a1fe274 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -419,13 +419,16 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs * links will be considered as dependencies @see jalhyd#98 */ public resetResults(visited: string[] = [], symbol?: string, forceResetAllDependencies: boolean = false) { - visited.push(this.currentNub.uid); - // reset GUI results - this.resetFormResults(); - // reset model results - this.currentNub.resetResult(); - // reset the result panels of all forms depending on this one - ServiceFactory.formulaireService.resetAllDependingFormsResults(this, visited, symbol, forceResetAllDependencies); + // console.debug(`FormulaireDefinition.resetResults(${visited})`); + if (this.currentNub.result !== undefined) { + visited.push(this.currentNub.uid); + // reset GUI results + this.resetFormResults(); + // reset model results + this.currentNub.resetResult(); + // reset the result panels of all forms depending on this one + ServiceFactory.formulaireService.resetAllDependingFormsResults(this, visited, symbol, forceResetAllDependencies); + } } protected abstract compute(); diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts index 73b4df1c57061fdc65c6089d630d711ae8753a60..4400467c8535c95d25367bc66dca6ebf98e6db17 100644 --- a/src/app/formulaire/definition/form-prebarrage.ts +++ b/src/app/formulaire/definition/form-prebarrage.ts @@ -125,6 +125,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { * envoie un événement "nodeSelected" (on a cliqué sur un nœud) */ public nodeSelected(node: PbBassin | PbCloison) { + // console.debug(`FormulairePrebarrage.NodeSelected(${node?.uid})`); // did something change, or we just clicked again on the node that was already selected ? if (this._selectedItem !== node) { // store for results formatting @@ -199,6 +200,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { // interface Observer public update(sender: IObservable, data: any) { + // console.debug("FormulairePrebarrage.update:", data); super.update(sender, data); if (sender instanceof FormulairePbCloison) { if (data.action === "updateBasin") { @@ -300,6 +302,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { } public resetResults() { + // console.debug("FormulairePrebarrage.resetResults()"); const hasToRedraw = (this._currentNub.result !== undefined); super.resetResults(); // reset all children nubs diff --git a/src/app/formulaire/elements/pb-schema.ts b/src/app/formulaire/elements/pb-schema.ts index f9c5afae59c9c0c4d1be46bde74f8d073a04933d..7b0df1a73c89994b92b523a48db166286fc2f9e5 100644 --- a/src/app/formulaire/elements/pb-schema.ts +++ b/src/app/formulaire/elements/pb-schema.ts @@ -38,6 +38,7 @@ export class PbSchema extends FormulaireElement { /** Asks PbSchemaComponent to redraw the schema */ public refresh(nodeUidToSelect?: string) { + // console.debug(`PbSchema.refresh(${nodeUidToSelect})`); this.notifyObservers({ action: "refresh", value: nodeUidToSelect diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts index 9a1abbe1ab16e5bbec7b2d62599a1bd05d7dad45..868f2666bf1a8716d6717a942820c5c4ca8cbe2b 100644 --- a/src/app/services/formulaire.service.ts +++ b/src/app/services/formulaire.service.ts @@ -815,6 +815,7 @@ export class FormulaireService extends Observable { if (form) { const hadResults = form.hasResults; // form might not have a result, but still have another form depending on it ! + // console.debug(`FormulaireService.resetAllDependingFormsResults(form->${dn.uid})`); form.resetResults(visited); if (hadResults) { if (notify) {