diff --git a/src/app/components/pb-results/pb-results-table.component.ts b/src/app/components/pb-results/pb-results-table.component.ts index 6838becaccafc979566c3cc9f95831100edd164a..79084192dd3b7b5e0477157ea06f3e8a09b1e5c9 100644 --- a/src/app/components/pb-results/pb-results-table.component.ts +++ b/src/app/components/pb-results/pb-results-table.component.ts @@ -45,7 +45,6 @@ export class PbResultsTableComponent extends ResultsComponentDirective implement } public ngOnChanges() { - console.log(">>>>>>> on changes ! drawing pb results table", this.variableIndex); this._dataSet = []; if ( this._pbResults diff --git a/src/app/components/pb-results/pb-results.component.ts b/src/app/components/pb-results/pb-results.component.ts index c63887407e34a7d4f47d38c81070ae606ac7eb28..80fd52db41a86f52df0c7fc92680540b4a150b05 100644 --- a/src/app/components/pb-results/pb-results.component.ts +++ b/src/app/components/pb-results/pb-results.component.ts @@ -4,7 +4,7 @@ import { CalculatorResults } from "../../results/calculator-results"; import { PrebarrageResults } from "../../results/prebarrage-results"; import { I18nService } from "../../services/internationalisation.service"; -import { cLog, Message, MessageCode, MessageSeverity, PbCloison, PreBarrage, Result } from "jalhyd"; +import { cLog, Message, MessageCode, MessageSeverity, PreBarrage, Result } from "jalhyd"; @Component({ selector: "pb-results", @@ -186,14 +186,12 @@ export class PbResultsComponent { } else { // B. si aucun paramètre ne varie this.mergeGlobalLog(this._pbResults.result, l); // faut bien mettre le log global quelque part - console.log("!!! ITERATION LOG !!! avant", l.messages.length); // logs des enfants for (const pbc of pb.children) { if (pbc?.result?.hasResultElements() && pbc.result.resultElement?.hasLog()) { l.addLog(pbc.result.resultElement.log); } } - console.log("!!! ITERATION LOG !!! après", l.messages.length); } } return l; diff --git a/src/app/components/pb-schema/pb-schema.component.scss b/src/app/components/pb-schema/pb-schema.component.scss index 9f4393f827da23efd5e24bfe66cae8c3b2ca5dd4..ea570e39cda9ed56a8d346f7a5b66b1c1be35cdd 100644 --- a/src/app/components/pb-schema/pb-schema.component.scss +++ b/src/app/components/pb-schema/pb-schema.component.scss @@ -74,6 +74,6 @@ mat-card-content { } } -/* #debug { +#debug { display: none; -} */ +} diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index faaec518822edfc64eb566aaeddf284a7d82ed1c..2dfe11e2fcfd53e4940a4a01a1a81e4c7d744b63 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -13,10 +13,10 @@ import { I18nService } from "../../services/internationalisation.service"; import { PbSchema } from "../../formulaire/elements/pb-schema"; import { DialogNewPbCloisonComponent } from "../dialog-new-pb-cloison/dialog-new-pb-cloison.component"; import { GenericCalculatorComponent } from "../generic-calculator/calculator.component"; +import { FormulairePrebarrage } from "../../formulaire/definition/form-prebarrage"; import { AppComponent } from "../../app.component"; import { fv } from "app/util"; -import { FormulairePrebarrage } from 'app/formulaire/definition/form-prebarrage'; /** * The interactive schema for calculator type "PreBarrage" (component) @@ -280,23 +280,28 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni let iDesc: string; if (item !== undefined) { iDesc = this.itemDescription(item); - if (item.result?.ok) { + if ( + item?.result?.resultElements + && item.result.resultElements[0]?.ok + ) { // when a parameter is variating, index of the variating parameter // values to build the data from const form = this.calculatorComponent.formulaire as FormulairePrebarrage; - console.log(">> found form", form.constructor.name); - console.log(">>> found idx", form?.pbResults?.variableIndex); const idx = form.pbResults.variableIndex; iDesc += "<br>"; if (item instanceof PbCloison) { - iDesc += "Q = " + fv(item.prms.Q.v); + iDesc += "Q = " + fv( + item.prms.Q.isCalculated + ? item.result.resultElements[idx].vCalc + : item.prms.Q.getInferredValuesList(this.model.variatingLength())[idx] + ); // @TODO chute /* iDesc += "\n"; iDesc += item.prms.DH.v; */ } else if (item instanceof PbBassin) { - iDesc += "PV = " + fv(item.result.resultElement.values.PV); + iDesc += "PV = " + fv(item.result.resultElements[idx].values.PV); iDesc += "<br>"; - iDesc += "YMOY = " + fv(item.result.resultElement.values.YMOY); + iDesc += "YMOY = " + fv(item.result.resultElements[idx].values.YMOY); } } } @@ -402,6 +407,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.refresh(); this.selectNodeOnSchema(wallCopy); this.clearResults(); + this.calculatorComponent.showPBInputData = true; } public get uitextCopy() { @@ -416,6 +422,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.refresh(); this.selectNodeOnSchema(newBasin); this.clearResults(); + this.calculatorComponent.showPBInputData = true; } public get uitextAddBasin() { @@ -450,6 +457,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.refresh(); this.selectNodeOnSchema(wall); this.clearResults(); + this.calculatorComponent.showPBInputData = true; } }); } @@ -475,6 +483,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.refresh(); this.selectNodeOnSchema(basin); this.clearResults(); + this.calculatorComponent.showPBInputData = true; } public get uitextMoveBasinUp() { @@ -498,6 +507,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.refresh(); this.selectNodeOnSchema(basin); this.clearResults(); + this.calculatorComponent.showPBInputData = true; } public get uitextMoveBasinDown() { @@ -548,6 +558,25 @@ 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(); + } + + /** + * Refreshes the schema; if uid is given, selects the node having this + * nub uid, else keeps previous selection + */ + private refreshWithSelection(uid ?: string) { + // remember previously selected node + const selectedNodeUID = this._selectedItem?.uid; + this.unselect(); + this.refresh(); + // select a specific node on the schema + if (uid !== undefined) { + this.selectNodeOnSchema(this.model.findChild(uid)); + } else if (selectedNodeUID !== undefined) { + // re-select previously selected node + this.selectNodeOnSchema(this.model.findChild(selectedNodeUID)); + } } // interface Observer @@ -555,12 +584,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni public update(sender: IObservable, data: any) { if (sender instanceof PbSchema) { if (data.action === "refresh") { - this.unselect(); - this.refresh(); - // select a node on the schema ? - if (data.value !== undefined) { - this.selectNodeOnSchema(this.model.findChild(data.value)); - } + this.refreshWithSelection(data.value); } } } diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts index d03decf7873833038bb2b83bddb77ef25962ad8b..61ac7d5f84d71bf08b97c76b43d382934b95c1be 100644 --- a/src/app/formulaire/definition/form-prebarrage.ts +++ b/src/app/formulaire/definition/form-prebarrage.ts @@ -41,6 +41,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { constructor() { super(); this._pbResults = new PrebarrageResults(); + this._pbResults.addObserver(this); } public get selectedItem(): PbBassin | PbCloison { @@ -185,7 +186,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { } } - private refreshSchema(nodeUidToSelect: string) { + private refreshSchema(nodeUidToSelect?: string) { const pbs = this.kids[0] as PbSchema; pbs.refresh(nodeUidToSelect); } @@ -199,6 +200,11 @@ export class FormulairePrebarrage extends FormulaireFixedVar { this.refreshSchema(data.value); } } + if (sender instanceof PrebarrageResults) { + if (data.action === "updateSchema") { + this.refreshSchema(); + } + } } protected compute() { @@ -209,6 +215,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { pbr.variableIndex = 0; this.reaffectResultComponents(); + this.refreshSchema(); } protected reaffectResultComponents() { @@ -299,5 +306,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { k.reset(); } } + // redraw schema to remove calc results in node boxes + this.refreshSchema(); } } diff --git a/src/app/formulaire/elements/pb-schema.ts b/src/app/formulaire/elements/pb-schema.ts index 278b7fe395f18c814bdf3774d4c92df4b8f8309d..f9c5afae59c9c0c4d1be46bde74f8d073a04933d 100644 --- a/src/app/formulaire/elements/pb-schema.ts +++ b/src/app/formulaire/elements/pb-schema.ts @@ -37,7 +37,7 @@ export class PbSchema extends FormulaireElement { } /** Asks PbSchemaComponent to redraw the schema */ - public refresh(nodeUidToSelect: string) { + public refresh(nodeUidToSelect?: string) { this.notifyObservers({ action: "refresh", value: nodeUidToSelect diff --git a/src/app/results/prebarrage-results.ts b/src/app/results/prebarrage-results.ts index c57f92501500004dd37b89ad4dd54ea5abc26613..0c734ae512e0964dff88a58cffa582a3c99c5165 100644 --- a/src/app/results/prebarrage-results.ts +++ b/src/app/results/prebarrage-results.ts @@ -1,10 +1,10 @@ -import { PreBarrage, Result } from "jalhyd"; +import { IObservable, Observable, Observer, PreBarrage, Result } from "jalhyd"; import { ServiceFactory } from "../services/service-factory"; import { MultiDimensionResults } from "./multidimension-results"; import { PbCloisonResults } from "./pb-cloison-results"; -export class PrebarrageResults extends MultiDimensionResults { +export class PrebarrageResults extends MultiDimensionResults implements IObservable { /** résultats des bassins, dans l'ordre */ public bassinsResults: Result[]; @@ -21,8 +21,12 @@ export class PrebarrageResults extends MultiDimensionResults { /** Stores appropriate number suffix for a given wall uid (copied from PbSchema) */ public wallsSuffixes: { [key: string]: number } = {}; + /** Implémentation par délégation */ + private _observable: Observable; + public constructor() { super(); + this._observable = new Observable(); this.reset(); this.size = 1; // boulette-proufe // standard headers @@ -66,6 +70,10 @@ export class PrebarrageResults extends MultiDimensionResults { this._variableIndex = v; // set index in pseudo-fixed Cloison results too this.cloisonResults.variableIndex = v; + // refresh schema + this.notifyObservers({ + action: "updateSchema" + }, this); } public reset() { @@ -108,6 +116,7 @@ export class PrebarrageResults extends MultiDimensionResults { public get basinResultsHaveData(): boolean { return ( this.bassinsResults.length > 0 + && this.bassinsResults[0] !== undefined && this.bassinsResults[0].resultElements[this.variableIndex] !== undefined && this.bassinsResults[0].resultElements[this.variableIndex].ok ); @@ -153,4 +162,27 @@ export class PrebarrageResults extends MultiDimensionResults { return err; } + + // interface IObservable + + /** + * ajoute un observateur à la liste + */ + public addObserver(o: Observer) { + this._observable.addObserver(o); + } + + /** + * supprime un observateur de la liste + */ + public removeObserver(o: Observer) { + this._observable.removeObserver(o); + } + + /** + * notifie un événement aux observateurs + */ + public notifyObservers(data: any, sender?: any) { + this._observable.notifyObservers(data, sender); + } }