Commit 2ceea376 authored by Mathias Chouet's avatar Mathias Chouet :spaghetti:
Browse files

Fix #246 - Update PreBarrage schema after calculation

Showing with 85 additions and 23 deletions
+85 -23
...@@ -45,7 +45,6 @@ export class PbResultsTableComponent extends ResultsComponentDirective implement ...@@ -45,7 +45,6 @@ export class PbResultsTableComponent extends ResultsComponentDirective implement
} }
public ngOnChanges() { public ngOnChanges() {
console.log(">>>>>>> on changes ! drawing pb results table", this.variableIndex);
this._dataSet = []; this._dataSet = [];
if ( if (
this._pbResults this._pbResults
......
...@@ -4,7 +4,7 @@ import { CalculatorResults } from "../../results/calculator-results"; ...@@ -4,7 +4,7 @@ import { CalculatorResults } from "../../results/calculator-results";
import { PrebarrageResults } from "../../results/prebarrage-results"; import { PrebarrageResults } from "../../results/prebarrage-results";
import { I18nService } from "../../services/internationalisation.service"; 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({ @Component({
selector: "pb-results", selector: "pb-results",
...@@ -186,14 +186,12 @@ export class PbResultsComponent { ...@@ -186,14 +186,12 @@ export class PbResultsComponent {
} else { } else {
// B. si aucun paramètre ne varie // B. si aucun paramètre ne varie
this.mergeGlobalLog(this._pbResults.result, l); // faut bien mettre le log global quelque part 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 // logs des enfants
for (const pbc of pb.children) { for (const pbc of pb.children) {
if (pbc?.result?.hasResultElements() && pbc.result.resultElement?.hasLog()) { if (pbc?.result?.hasResultElements() && pbc.result.resultElement?.hasLog()) {
l.addLog(pbc.result.resultElement.log); l.addLog(pbc.result.resultElement.log);
} }
} }
console.log("!!! ITERATION LOG !!! après", l.messages.length);
} }
} }
return l; return l;
......
...@@ -74,6 +74,6 @@ mat-card-content { ...@@ -74,6 +74,6 @@ mat-card-content {
} }
} }
/* #debug { #debug {
display: none; display: none;
} */ }
...@@ -13,10 +13,10 @@ import { I18nService } from "../../services/internationalisation.service"; ...@@ -13,10 +13,10 @@ import { I18nService } from "../../services/internationalisation.service";
import { PbSchema } from "../../formulaire/elements/pb-schema"; import { PbSchema } from "../../formulaire/elements/pb-schema";
import { DialogNewPbCloisonComponent } from "../dialog-new-pb-cloison/dialog-new-pb-cloison.component"; import { DialogNewPbCloisonComponent } from "../dialog-new-pb-cloison/dialog-new-pb-cloison.component";
import { GenericCalculatorComponent } from "../generic-calculator/calculator.component"; import { GenericCalculatorComponent } from "../generic-calculator/calculator.component";
import { FormulairePrebarrage } from "../../formulaire/definition/form-prebarrage";
import { AppComponent } from "../../app.component"; import { AppComponent } from "../../app.component";
import { fv } from "app/util"; import { fv } from "app/util";
import { FormulairePrebarrage } from 'app/formulaire/definition/form-prebarrage';
/** /**
* The interactive schema for calculator type "PreBarrage" (component) * The interactive schema for calculator type "PreBarrage" (component)
...@@ -280,23 +280,28 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni ...@@ -280,23 +280,28 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
let iDesc: string; let iDesc: string;
if (item !== undefined) { if (item !== undefined) {
iDesc = this.itemDescription(item); 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 // when a parameter is variating, index of the variating parameter
// values to build the data from // values to build the data from
const form = this.calculatorComponent.formulaire as FormulairePrebarrage; 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; const idx = form.pbResults.variableIndex;
iDesc += "<br>"; iDesc += "<br>";
if (item instanceof PbCloison) { 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 // @TODO chute
/* iDesc += "\n"; /* iDesc += "\n";
iDesc += item.prms.DH.v; */ iDesc += item.prms.DH.v; */
} else if (item instanceof PbBassin) { } 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 += "<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 ...@@ -402,6 +407,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
this.refresh(); this.refresh();
this.selectNodeOnSchema(wallCopy); this.selectNodeOnSchema(wallCopy);
this.clearResults(); this.clearResults();
this.calculatorComponent.showPBInputData = true;
} }
public get uitextCopy() { public get uitextCopy() {
...@@ -416,6 +422,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni ...@@ -416,6 +422,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
this.refresh(); this.refresh();
this.selectNodeOnSchema(newBasin); this.selectNodeOnSchema(newBasin);
this.clearResults(); this.clearResults();
this.calculatorComponent.showPBInputData = true;
} }
public get uitextAddBasin() { public get uitextAddBasin() {
...@@ -450,6 +457,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni ...@@ -450,6 +457,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
this.refresh(); this.refresh();
this.selectNodeOnSchema(wall); this.selectNodeOnSchema(wall);
this.clearResults(); this.clearResults();
this.calculatorComponent.showPBInputData = true;
} }
}); });
} }
...@@ -475,6 +483,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni ...@@ -475,6 +483,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
this.refresh(); this.refresh();
this.selectNodeOnSchema(basin); this.selectNodeOnSchema(basin);
this.clearResults(); this.clearResults();
this.calculatorComponent.showPBInputData = true;
} }
public get uitextMoveBasinUp() { public get uitextMoveBasinUp() {
...@@ -498,6 +507,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni ...@@ -498,6 +507,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
this.refresh(); this.refresh();
this.selectNodeOnSchema(basin); this.selectNodeOnSchema(basin);
this.clearResults(); this.clearResults();
this.calculatorComponent.showPBInputData = true;
} }
public get uitextMoveBasinDown() { public get uitextMoveBasinDown() {
...@@ -548,6 +558,25 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni ...@@ -548,6 +558,25 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
/** clear all PB form results whenever the basins / walls layout is changed */ /** clear all PB form results whenever the basins / walls layout is changed */
private clearResults() { private clearResults() {
this.pbSchema.form.reset(); 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 // interface Observer
...@@ -555,12 +584,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni ...@@ -555,12 +584,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
public update(sender: IObservable, data: any) { public update(sender: IObservable, data: any) {
if (sender instanceof PbSchema) { if (sender instanceof PbSchema) {
if (data.action === "refresh") { if (data.action === "refresh") {
this.unselect(); this.refreshWithSelection(data.value);
this.refresh();
// select a node on the schema ?
if (data.value !== undefined) {
this.selectNodeOnSchema(this.model.findChild(data.value));
}
} }
} }
} }
......
...@@ -41,6 +41,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { ...@@ -41,6 +41,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
constructor() { constructor() {
super(); super();
this._pbResults = new PrebarrageResults(); this._pbResults = new PrebarrageResults();
this._pbResults.addObserver(this);
} }
public get selectedItem(): PbBassin | PbCloison { public get selectedItem(): PbBassin | PbCloison {
...@@ -185,7 +186,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { ...@@ -185,7 +186,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
} }
} }
private refreshSchema(nodeUidToSelect: string) { private refreshSchema(nodeUidToSelect?: string) {
const pbs = this.kids[0] as PbSchema; const pbs = this.kids[0] as PbSchema;
pbs.refresh(nodeUidToSelect); pbs.refresh(nodeUidToSelect);
} }
...@@ -199,6 +200,11 @@ export class FormulairePrebarrage extends FormulaireFixedVar { ...@@ -199,6 +200,11 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
this.refreshSchema(data.value); this.refreshSchema(data.value);
} }
} }
if (sender instanceof PrebarrageResults) {
if (data.action === "updateSchema") {
this.refreshSchema();
}
}
} }
protected compute() { protected compute() {
...@@ -209,6 +215,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { ...@@ -209,6 +215,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
pbr.variableIndex = 0; pbr.variableIndex = 0;
this.reaffectResultComponents(); this.reaffectResultComponents();
this.refreshSchema();
} }
protected reaffectResultComponents() { protected reaffectResultComponents() {
...@@ -299,5 +306,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { ...@@ -299,5 +306,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
k.reset(); k.reset();
} }
} }
// redraw schema to remove calc results in node boxes
this.refreshSchema();
} }
} }
...@@ -37,7 +37,7 @@ export class PbSchema extends FormulaireElement { ...@@ -37,7 +37,7 @@ export class PbSchema extends FormulaireElement {
} }
/** Asks PbSchemaComponent to redraw the schema */ /** Asks PbSchemaComponent to redraw the schema */
public refresh(nodeUidToSelect: string) { public refresh(nodeUidToSelect?: string) {
this.notifyObservers({ this.notifyObservers({
action: "refresh", action: "refresh",
value: nodeUidToSelect value: nodeUidToSelect
......
import { PreBarrage, Result } from "jalhyd"; import { IObservable, Observable, Observer, PreBarrage, Result } from "jalhyd";
import { ServiceFactory } from "../services/service-factory"; import { ServiceFactory } from "../services/service-factory";
import { MultiDimensionResults } from "./multidimension-results"; import { MultiDimensionResults } from "./multidimension-results";
import { PbCloisonResults } from "./pb-cloison-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 */ /** résultats des bassins, dans l'ordre */
public bassinsResults: Result[]; public bassinsResults: Result[];
...@@ -21,8 +21,12 @@ export class PrebarrageResults extends MultiDimensionResults { ...@@ -21,8 +21,12 @@ export class PrebarrageResults extends MultiDimensionResults {
/** Stores appropriate number suffix for a given wall uid (copied from PbSchema) */ /** Stores appropriate number suffix for a given wall uid (copied from PbSchema) */
public wallsSuffixes: { [key: string]: number } = {}; public wallsSuffixes: { [key: string]: number } = {};
/** Implémentation par délégation */
private _observable: Observable;
public constructor() { public constructor() {
super(); super();
this._observable = new Observable();
this.reset(); this.reset();
this.size = 1; // boulette-proufe this.size = 1; // boulette-proufe
// standard headers // standard headers
...@@ -66,6 +70,10 @@ export class PrebarrageResults extends MultiDimensionResults { ...@@ -66,6 +70,10 @@ export class PrebarrageResults extends MultiDimensionResults {
this._variableIndex = v; this._variableIndex = v;
// set index in pseudo-fixed Cloison results too // set index in pseudo-fixed Cloison results too
this.cloisonResults.variableIndex = v; this.cloisonResults.variableIndex = v;
// refresh schema
this.notifyObservers({
action: "updateSchema"
}, this);
} }
public reset() { public reset() {
...@@ -108,6 +116,7 @@ export class PrebarrageResults extends MultiDimensionResults { ...@@ -108,6 +116,7 @@ export class PrebarrageResults extends MultiDimensionResults {
public get basinResultsHaveData(): boolean { public get basinResultsHaveData(): boolean {
return ( return (
this.bassinsResults.length > 0 this.bassinsResults.length > 0
&& this.bassinsResults[0] !== undefined
&& this.bassinsResults[0].resultElements[this.variableIndex] !== undefined && this.bassinsResults[0].resultElements[this.variableIndex] !== undefined
&& this.bassinsResults[0].resultElements[this.variableIndex].ok && this.bassinsResults[0].resultElements[this.variableIndex].ok
); );
...@@ -153,4 +162,27 @@ export class PrebarrageResults extends MultiDimensionResults { ...@@ -153,4 +162,27 @@ export class PrebarrageResults extends MultiDimensionResults {
return err; 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);
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment