From a7c98a72dd16eb6db55bfc32c2d0c5594d78f7c6 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Thu, 4 Jul 2019 18:06:46 +0200 Subject: [PATCH] Fix #230 : faire varier les conditions limites --- src/app/app.module.ts | 2 + .../fixedvar-results/var-results.component.ts | 2 +- .../calculator.component.html | 2 + .../calculator.component.scss | 10 +- .../pab-results-table.component.scss | 1 - .../pab-results-table.component.ts | 19 ++-- .../pab-results/pab-results.component.html | 3 + .../pab-results/pab-results.component.ts | 22 +++- ...b-variable-results-selector.component.html | 11 ++ ...b-variable-results-selector.component.scss | 10 ++ ...pab-variable-results-selector.component.ts | 104 ++++++++++++++++++ .../param-values/param-values.component.ts | 2 +- .../formulaire/definition/form-compute-pab.ts | 17 ++- src/app/results/pab-results.ts | 7 +- src/app/results/plottable-pab-results.ts | 17 +-- .../services/formulaire/formulaire.service.ts | 14 ++- src/locale/messages.en.json | 1 + src/locale/messages.fr.json | 1 + 18 files changed, 210 insertions(+), 35 deletions(-) create mode 100644 src/app/components/pab-results/pab-variable-results-selector.component.html create mode 100644 src/app/components/pab-results/pab-variable-results-selector.component.scss create mode 100644 src/app/components/pab-results/pab-variable-results-selector.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index abc74247e..ae38d7ea0 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -80,6 +80,7 @@ import { LogEntryComponent } from "./components/log-entry/log-entry.component"; import { ParamLinkComponent } from "./components/param-link/param-link.component"; import { SelectModelFieldLineComponent } from "./components/select-model-field-line/select-model-field-line.component"; import { PabTableComponent } from "./components/pab-table/pab-table.component"; +import { PabVariableResultsSelectorComponent } from "./components/pab-results/pab-variable-results-selector.component"; import { DialogConfirmEmptySessionComponent } from "./components/dialog-confirm-empty-session/dialog-confirm-empty-session.component"; import { DialogConfirmCloseCalcComponent } from "./components/dialog-confirm-close-calc/dialog-confirm-close-calc.component"; @@ -185,6 +186,7 @@ const appRoutes: Routes = [ PabResultsComponent, PabResultsTableComponent, PabTableComponent, + PabVariableResultsSelectorComponent, ParamComputedComponent, ParamFieldLineComponent, ParamLinkComponent, diff --git a/src/app/components/fixedvar-results/var-results.component.ts b/src/app/components/fixedvar-results/var-results.component.ts index 7a97e80c6..424e43423 100644 --- a/src/app/components/fixedvar-results/var-results.component.ts +++ b/src/app/components/fixedvar-results/var-results.component.ts @@ -72,7 +72,7 @@ export class VarResultsComponent extends ResultsComponent { } this._headers = this._headers.concat(this._varResults.extraResultHeaders); - // C. pre-extract variable parameters valueslet longest = 0; + // C. pre-extract variable parameters values const varValues = []; // find longest list this.size = 0; diff --git a/src/app/components/generic-calculator/calculator.component.html b/src/app/components/generic-calculator/calculator.component.html index 72238c220..f3fb61d6c 100644 --- a/src/app/components/generic-calculator/calculator.component.html +++ b/src/app/components/generic-calculator/calculator.component.html @@ -34,6 +34,7 @@ <!-- chapitres --> <mat-card id="calc-card-field-sets" + [class.pab-field-sets]="isPAB" [fxFlex.gt-xs]="isPAB ? '1 0 auto' : '1 0 400px'" [fxFlex.lt-sm]="isPAB ? '1 0 auto' : '1 0 300px'"> @@ -63,6 +64,7 @@ <!-- résultats --> <mat-card id="calc-card-results" + [class.pab-results]="isPAB" [fxFlex.gt-xs]="isPAB ? '1 0 auto' : '1 0 400px'" [fxFlex.lt-sm]="isPAB ? '1 0 auto' : '1 0 300px'"> diff --git a/src/app/components/generic-calculator/calculator.component.scss b/src/app/components/generic-calculator/calculator.component.scss index c9cbd66b2..e1e07ee87 100644 --- a/src/app/components/generic-calculator/calculator.component.scss +++ b/src/app/components/generic-calculator/calculator.component.scss @@ -38,6 +38,10 @@ mat-card { margin-left: 1em; margin-right: 1em; + &.pab-field-sets { + margin-right: -1em; + } + mat-card-actions { text-align: center; @@ -51,8 +55,12 @@ mat-card { margin-left: 1em; margin-right: 1em; + &.pab-results { + margin-right: -1em; + } + mat-card-header { - margin-bottom: 1em; + // margin-bottom: 1em; #generate-pab { height: min-content; diff --git a/src/app/components/pab-results/pab-results-table.component.scss b/src/app/components/pab-results/pab-results-table.component.scss index 7e227e04e..ea1d83f80 100644 --- a/src/app/components/pab-results/pab-results-table.component.scss +++ b/src/app/components/pab-results/pab-results-table.component.scss @@ -3,7 +3,6 @@ } .pab-results-table-container { - margin-top: 2em; background-color: white; } diff --git a/src/app/components/pab-results/pab-results-table.component.ts b/src/app/components/pab-results/pab-results-table.component.ts index 959e2a848..707d73cf9 100644 --- a/src/app/components/pab-results/pab-results-table.component.ts +++ b/src/app/components/pab-results/pab-results-table.component.ts @@ -46,15 +46,18 @@ export class PabResultsTableComponent extends ResultsComponent { ) { const pr = this._pabResults; const nDigits = this.appSetupService.displayDigits; + // when a parameter is variating, index of the variating parameter + // values to build the data from + const vi = pr.variableIndex; // refresh headers here if language changed this._headers = pr.headers; // line 1 - if (pr.cloisonsResults[0].vCalc) { // parfois le calcul des cloisons échoue + if (pr.cloisonsResults[0].resultElements[vi].vCalc) { // parfois le calcul des cloisons échoue this._dataSet.push([ this.intlService.localizeText("INFO_LIB_AMONT"), - pr.cloisonsResults[0] ? pr.cloisonsResults[0].vCalc.toFixed(nDigits) : "", + pr.cloisonsResults[0].resultElements[vi] ? pr.cloisonsResults[0].resultElements[vi].vCalc.toFixed(nDigits) : "", "", "", "", "", "", "", "" ]); } @@ -62,14 +65,14 @@ export class PabResultsTableComponent extends ResultsComponent { // lines 2 - n-1 for (let i = 0; i < pr.cloisonsResults.length; i++) { if ( - pr.cloisonsResults[i].vCalc + pr.cloisonsResults[i].resultElements[vi].vCalc ) { - const r2n = pr.cloisonsResults[i].resultElement.extraResults; + const r2n = pr.cloisonsResults[i].resultElements[vi].extraResults; let Z1: number; if (i < pr.cloisonsResults.length - 1) { - Z1 = pr.cloisonsResults[i + 1].vCalc; + Z1 = pr.cloisonsResults[i + 1].resultElements[vi].vCalc; } else { - Z1 = pr.cloisonAvalResults.vCalc; + Z1 = pr.cloisonAvalResults.resultElements[vi].vCalc; } this._dataSet.push([ i + 1, // n° cloison @@ -86,8 +89,8 @@ export class PabResultsTableComponent extends ResultsComponent { } // downstream line - if (pr.cloisonAvalResults.vCalc) { - const rln = pr.cloisonAvalResults.resultElement.extraResults; + if (pr.cloisonAvalResults.resultElements[vi].vCalc) { + const rln = pr.cloisonAvalResults.resultElements[vi].extraResults; this._dataSet.push([ this.intlService.localizeText("INFO_LIB_AVAL"), pr.Z2.toFixed(nDigits), diff --git a/src/app/components/pab-results/pab-results.component.html b/src/app/components/pab-results/pab-results.component.html index ed25a06e7..3db5bfb1c 100644 --- a/src/app/components/pab-results/pab-results.component.html +++ b/src/app/components/pab-results/pab-results.component.html @@ -2,6 +2,9 @@ <!-- journal --> <log></log> + <pab-variable-results-selector [results]="pabResults" (indexChange)="variableIndexChanged()"> + </pab-variable-results-selector> + <div> <!-- tableau de résultats --> <pab-results-table [results]="pabResults"></pab-results-table> diff --git a/src/app/components/pab-results/pab-results.component.ts b/src/app/components/pab-results/pab-results.component.ts index d17318d76..2abe47a9b 100644 --- a/src/app/components/pab-results/pab-results.component.ts +++ b/src/app/components/pab-results/pab-results.component.ts @@ -8,9 +8,10 @@ import { NgParameter } from "../../formulaire/ngparam"; import { ApplicationSetupService } from "../../services/app-setup/app-setup.service"; import { PabResultsTableComponent } from "./pab-results-table.component"; import { PabResults } from "../../results/pab-results"; -import { ResultsGraphComponent } from "../results-graph/results-graph.component"; +import { PabVariableResultsSelectorComponent } from "./pab-variable-results-selector.component"; import { PlottableData } from "../../results/plottable-data"; import { PlottablePabResults } from "../../results/plottable-pab-results"; +import { ResultsGraphComponent } from "../results-graph/results-graph.component"; @Component({ selector: "pab-results", @@ -33,11 +34,12 @@ export class PabResultsComponent implements DoCheck { @ViewChild(PabResultsTableComponent) private pabResultsTableComponent: PabResultsTableComponent; - /** composant journal */ + @ViewChild(PabVariableResultsSelectorComponent) + private pabVariableResultsSelectorComponent: PabVariableResultsSelectorComponent; + @ViewChild(LogComponent) private logComponent: LogComponent; - /** graphique dans le cas d'un paramètre à varier */ @ViewChild(ResultsGraphComponent) private resultsGraphComponent: ResultsGraphComponent; @@ -55,11 +57,24 @@ export class PabResultsComponent implements DoCheck { this.updateView(); } + /** + * update results table and chart when the variable index changed (event sent by + * PabVariableResultsSelectorComponent); variable index is already set in + * pabResults at this time + */ + public variableIndexChanged() { + console.log("oulala l'index variableu qui change !!"); + this.updateView(); + } + public updateView() { this.logComponent.log = undefined; if (this.pabResultsTableComponent) { this.pabResultsTableComponent.results = undefined; } + if (this.pabVariableResultsSelectorComponent) { + this.pabVariableResultsSelectorComponent.results = undefined; + } if (this.resultsGraphComponent) { this.resultsGraphComponent.results = undefined; } @@ -111,6 +126,7 @@ export class PabResultsComponent implements DoCheck { pabUpdated = this.pabResultsTableComponent !== undefined; if (pabUpdated) { this.pabResultsTableComponent.results = this._pabResults; + this.pabVariableResultsSelectorComponent.results = this._pabResults; } graphUpdated = this.resultsGraphComponent !== undefined; if (graphUpdated) { diff --git a/src/app/components/pab-results/pab-variable-results-selector.component.html b/src/app/components/pab-results/pab-variable-results-selector.component.html new file mode 100644 index 000000000..a6cc6df24 --- /dev/null +++ b/src/app/components/pab-results/pab-variable-results-selector.component.html @@ -0,0 +1,11 @@ +<div class="pab-variable-results-selector" *ngIf="hasVariableResults" fxLayout="row wrap" fxLayoutAlign="center center"> + <div fxFlex="1 1 100%"> + <mat-form-field> + <mat-select id="pab-variating-element" [placeholder]="label" [(value)]="selectedValue"> + <mat-option *ngFor="let e of entries" [value]="e"> + {{ entryLabel(e) }} + </mat-option> + </mat-select> + </mat-form-field> + </div> +</div> diff --git a/src/app/components/pab-results/pab-variable-results-selector.component.scss b/src/app/components/pab-results/pab-variable-results-selector.component.scss new file mode 100644 index 000000000..d3c5d0c6d --- /dev/null +++ b/src/app/components/pab-results/pab-variable-results-selector.component.scss @@ -0,0 +1,10 @@ +:host { + margin-top: 2em; +} + +mat-form-field { + width: 100%; + max-width: 400px; + margin-top: 1em; + margin-bottom: -1em; +} diff --git a/src/app/components/pab-results/pab-variable-results-selector.component.ts b/src/app/components/pab-results/pab-variable-results-selector.component.ts new file mode 100644 index 000000000..62112d7b8 --- /dev/null +++ b/src/app/components/pab-results/pab-variable-results-selector.component.ts @@ -0,0 +1,104 @@ +import { Component, Output, EventEmitter } from "@angular/core"; + +import { PabResults } from "../../results/pab-results"; +import { I18nService } from "../../services/internationalisation/internationalisation.service"; +import { ApplicationSetupService } from "../../services/app-setup/app-setup.service"; + +@Component({ + selector: "pab-variable-results-selector", + templateUrl: "./pab-variable-results-selector.component.html", + styleUrls: [ + "./pab-variable-results-selector.component.scss" + ] +}) +export class PabVariableResultsSelectorComponent { + + /** résultats non mis en forme */ + private _pabResults: PabResults; + + private _selectedValue: number; + + /** size of the longest variable value */ + private size = 0; + + /** inferred extended values list for each variating parameter */ + private varValues = []; + + @Output() + protected indexChange = new EventEmitter(); + + constructor( + protected intlService: I18nService, + protected appSetupService: ApplicationSetupService + ) { + this._selectedValue = 0; + } + + public set results(r: PabResults) { + this._pabResults = r; + + if (this._pabResults) { + // pre-extract variable parameters values + this.varValues = []; + const nDigits = this.appSetupService.displayDigits; + // find longest list + this.size = 0; + for (let i = 0; i < this._pabResults.variatedParameters.length; i++) { + const vs = this._pabResults.variatedParameters[i].valuesIterator.count(); + if (vs > this.size) { + this.size = vs; + } + } + // get extended values lists for each variable parameter + for (const v of this._pabResults.variatedParameters) { + const vv = []; + const iter = v.getExtendedValuesIterator(this.size); + while (iter.hasNext) { + const nv = iter.next(); + vv.push(nv.value.toFixed(nDigits)); + } + this.varValues.push(vv); + } + } + } + + public get hasVariableResults(): boolean { + return ( + this._pabResults + && this._pabResults.hasResults + && this._pabResults.variatedParameters.length > 0 + ); + } + + public get entries(): number[] { + let i = 0; + const entries: number[] = this._pabResults.variatedParameters[0].inferredValuesList.map((v) => { + return i++; + }); + return entries; + } + + protected entryLabel(index: number): string { + let i = 0; + return this.varValues.map((vv) => { + const vp = this._pabResults.variatedParameters[i]; + i++; + let value = "0"; + value = vv[index]; + return `${vp.symbol} = ${value}`; + }).join(", "); + } + + public get selectedValue(): number { + return this._selectedValue; + } + + public set selectedValue(v: number) { + this._pabResults.variableIndex = v; + this.indexChange.emit(); + } + + public get label() { + return this.intlService.localizeText("INFO_PARAMFIELD_BOUNDARY_CONDITIONS"); + } +} diff --git a/src/app/components/param-values/param-values.component.ts b/src/app/components/param-values/param-values.component.ts index 41cefb196..3e1e933d5 100644 --- a/src/app/components/param-values/param-values.component.ts +++ b/src/app/components/param-values/param-values.component.ts @@ -57,7 +57,7 @@ export class ParamValuesComponent implements AfterViewInit, Observer { this.editValuesDialog.open( DialogEditParamValuesComponent, { - disableClose: true, + disableClose: false, data: { param: this.param }, diff --git a/src/app/formulaire/definition/form-compute-pab.ts b/src/app/formulaire/definition/form-compute-pab.ts index 58f52cc07..ce39c432d 100644 --- a/src/app/formulaire/definition/form-compute-pab.ts +++ b/src/app/formulaire/definition/form-compute-pab.ts @@ -15,18 +15,15 @@ export class FormComputePab extends FormCompute { return this._formResult as FormResultPab; } - private getVariatedParameter(): NgParameter { - const res = this._formBase.getDisplayedParamFromState(ParamRadioConfig.VAR); - if (res !== undefined) { - return res; - } - + private getVariatedParameters(): NgParameter[] { + const res = this._formBase.getDisplayedParamListFromState(ParamRadioConfig.VAR); const pms = this._formBase.getDisplayedParamListFromState(ParamRadioConfig.LINK); for (const p of pms) { if (p.paramDefinition.hasMultipleValues) { - return p; + res.push(p); } } + return res; } protected compute() { @@ -37,7 +34,7 @@ export class FormComputePab extends FormCompute { protected reaffectResultComponents() { const pab: Pab = (this._formBase.currentNub as Pab); const computedParam: NgParameter = this.getComputedParameter(); - const varParam: NgParameter = this.getVariatedParameter(); + const varParams: NgParameter[] = this.getVariatedParameters(); // résultat de calcul de la passe à bassins const pabr = this.formResult.pabResults; @@ -55,8 +52,8 @@ export class FormComputePab extends FormCompute { // cote aval de la passe pabr.Z2 = pab.prms.Z2.v; - if (varParam) { - pabr.variatedParameter = varParam; + if (varParams) { + pabr.variatedParameters = varParams; // pabr.update(false); } } diff --git a/src/app/results/pab-results.ts b/src/app/results/pab-results.ts index 592708994..334882bfe 100644 --- a/src/app/results/pab-results.ts +++ b/src/app/results/pab-results.ts @@ -15,8 +15,11 @@ export class PabResults extends CalculatedParamResults { /** cote aval de l'ensemble de la passe */ public Z2: number; - /** paramètre varié */ - public variatedParameter: NgParameter; + /** paramètres variés */ + public variatedParameters: NgParameter[]; + + /** index de la valeur du paramètre varié à afficher dans les résultats */ + public variableIndex = 0; /** symboles des colonnes de résultat */ protected _columns: string[]; diff --git a/src/app/results/plottable-pab-results.ts b/src/app/results/plottable-pab-results.ts index bcfa6cf53..85bd80a19 100644 --- a/src/app/results/plottable-pab-results.ts +++ b/src/app/results/plottable-pab-results.ts @@ -64,6 +64,9 @@ export class PlottablePabResults implements PlottableData { const pr = this.pabResults; const nDigits = ServiceFactory.instance.applicationSetupService.displayDigits; const l = this.pabResults.cloisonsResults.length; + // when a parameter is variating, index of the variating parameter + // values to build the data from + const vi = this.pabResults.variableIndex; if (this.hasError()) { return []; @@ -82,18 +85,18 @@ export class PlottablePabResults implements PlottableData { case "Q": data.push(""); for (let i = 0; i < l; i++) { - const er = pr.cloisonsResults[i].getExtraResult(symbol); + const er = pr.cloisonsResults[i].resultElements[vi].getExtraResult(symbol); data.push((er !== undefined) ? er.toFixed(nDigits) : ""); } - const zrAval = pr.cloisonAvalResults.getExtraResult(symbol); + const zrAval = pr.cloisonAvalResults.resultElements[vi].getExtraResult(symbol); data.push((zrAval !== undefined) ? zrAval.toFixed(nDigits) : ""); break; case "Z": for (let i = 0; i < l; i++) { - data.push(pr.cloisonsResults[i].vCalc.toFixed(nDigits)); + data.push(pr.cloisonsResults[i].resultElements[vi].vCalc.toFixed(nDigits)); } - data.push(pr.cloisonAvalResults.vCalc.toFixed(nDigits)); + data.push(pr.cloisonAvalResults.resultElements[vi].vCalc.toFixed(nDigits)); data.push(pr.Z2.toFixed(nDigits)); break; @@ -103,7 +106,7 @@ export class PlottablePabResults implements PlottableData { case "QA": data.push(""); for (let i = 0; i < l; i++) { - const er = pr.cloisonsResults[i].getExtraResult(symbol); + const er = pr.cloisonsResults[i].resultElements[vi].getExtraResult(symbol); data.push((er !== undefined) ? er.toFixed(nDigits) : ""); } data.push(""); @@ -112,10 +115,10 @@ export class PlottablePabResults implements PlottableData { case "x": // wall abscissa data.push(""); for (let i = 0; i < l; i++) { - const er = pr.cloisonsResults[i].getExtraResult(symbol); + const er = pr.cloisonsResults[i].resultElements[vi].getExtraResult(symbol); data.push((er !== undefined) ? er.toFixed(nDigits) : ""); } - const erXdw = pr.cloisonAvalResults.getExtraResult(symbol); + const erXdw = pr.cloisonAvalResults.resultElements[vi].getExtraResult(symbol); data.push((erXdw !== undefined) ? erXdw.toFixed(nDigits) : ""); break; } diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 5267f8902..6b6bb15e4 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -3,7 +3,19 @@ import { Injectable } from "@angular/core"; import { decode } from "he"; import { saveAs } from "file-saver"; -import { CalculatorType, LinkedValue, Observable, ParamDefinition, Session, Nub, ParallelStructure, Pab, Props, Cloisons } from "jalhyd"; +import { + CalculatorType, + LinkedValue, + Observable, + ParamDefinition, + Session, + Nub, + ParallelStructure, + Pab, + Props, + Cloisons, + CloisonAval +} from "jalhyd"; import { HttpService } from "../../services/http/http.service"; import { I18nService } from "../../services/internationalisation/internationalisation.service"; diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index 1abffb6c6..53fb506aa 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -250,6 +250,7 @@ "INFO_PARALLELSTRUCTURE_TITRE_COURT": "// structures", "INFO_PARALLELSTRUCTURE_TITRE": "Parallel structures", "INFO_PARAMFIELD_AWAITING_CALCULATION": "Awaiting calculation", + "INFO_PARAMFIELD_BOUNDARY_CONDITIONS": "Boundary conditions", "INFO_PARAMFIELD_CALCULATED": "Calculated", "INFO_PARAMFIELD_CALCULATION_FAILED": "Calculation failed", "INFO_PARAMFIELD_GRAPH_SELECT_X_AXIS": "Variable for X axis", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index db1a816be..33c863b89 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -250,6 +250,7 @@ "INFO_PARALLELSTRUCTURE_TITRE_COURT": "Ouvrages", "INFO_PARALLELSTRUCTURE_TITRE": "Lois d'ouvrages", "INFO_PARAMFIELD_AWAITING_CALCULATION": "En attente de calcul", + "INFO_PARAMFIELD_BOUNDARY_CONDITIONS": "Conditions aux limites", "INFO_PARAMFIELD_CALCULATED": "Calculé", "INFO_PARAMFIELD_CALCULATION_FAILED": "Échec du calcul", "INFO_PARAMFIELD_GRAPH_SELECT_X_AXIS": "Variable en abscisse", -- GitLab