From 3bddb33536ee5d6a7a4f86c16d4a29350ae6bac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Fri, 4 Nov 2022 08:28:55 +0100 Subject: [PATCH] feature : backwater curves: add select to open a parametric section calculator for a given abscissa refs #496 --- src/app/app.module.ts | 4 ++- .../calculator.component.html | 2 ++ .../calculator.component.ts | 21 ++++++++++++ .../select-section-details.component.html | 5 +++ .../select-section-details.component.scss | 3 ++ .../select-section-details.component.ts | 33 +++++++++++++++++++ src/app/results/remous-results.ts | 9 +++++ src/app/services/formulaire.service.ts | 16 +++++---- 8 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 src/app/components/select-section-details/select-section-details.component.html create mode 100644 src/app/components/select-section-details/select-section-details.component.scss create mode 100644 src/app/components/select-section-details/select-section-details.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index c5fd9324b..702dabc0e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -124,6 +124,7 @@ import { StructureFieldsetContainerComponent } from "./components/structure-fiel import { BasinFieldsetContainerComponent } from "./components/basin-fieldset-container/basin-fieldset-container.component"; import { PrebarrageService } from "./services/prebarrage.service"; import { SectionDetailsEntryComponent } from "./components/section-details-entry/section-details-entry.component"; +import { SelectSectionDetailsComponent } from "./components/select-section-details/select-section-details.component"; const appRoutes: Routes = [ { path: "list/search", component: CalculatorListComponent }, @@ -259,7 +260,8 @@ const appRoutes: Routes = [ SessionPropertiesComponent, VarResultsComponent, VerificateurResultsComponent, - SectionDetailsEntryComponent + SectionDetailsEntryComponent, + SelectSectionDetailsComponent ], providers: [ // services ApplicationSetupService, diff --git a/src/app/components/generic-calculator/calculator.component.html b/src/app/components/generic-calculator/calculator.component.html index a61455db0..80581c365 100644 --- a/src/app/components/generic-calculator/calculator.component.html +++ b/src/app/components/generic-calculator/calculator.component.html @@ -200,6 +200,8 @@ {{ uitextGenerateRuSp }} </button> + <select-section-details id="generate-cr-sps" *ngIf="hasCourbeRemousResults" [points]="courbeRemousAbscissae"></select-section-details> + <button mat-raised-button color="accent" id="generate-par-simulation" *ngIf="isPAR" (click)="generatePARSimulation()" [disabled]="! generatePARSimulationEnabled" [title]="uitextGenerateParSimulationTitle"> diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index fc57d1653..500b329de 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -63,6 +63,8 @@ import { sprintf } from "sprintf-js"; import * as XLSX from "xlsx"; import { ServiceFactory } from "app/services/service-factory"; import { DefinedBoolean } from "app/definedvalue/definedboolean"; +import { FormulaireCourbeRemous } from "app/formulaire/definition/form-courbe-remous"; +import { RemousResults } from "app/results/remous-results"; @Component({ selector: "hydrocalc", @@ -710,6 +712,11 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe return this.is(CalculatorType.RegimeUniforme); } + // true if CourbeRemous results are present + public get hasCourbeRemousResults() { + return this.is(CalculatorType.CourbeRemous) && this.hasResults; + } + // true if current Nub is PAR public get isPAR() { return this.is(CalculatorType.Par); @@ -972,6 +979,20 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe this.router.navigate(["/calculator", f.uid]); } + /** + * @returns liste des abscisses du graphe de courbes de remous + */ + public get courbeRemousAbscissae(): number[] { + if (this.hasCourbeRemousResults) { + const crForm = this._formulaire as FormulaireCourbeRemous; + for (const r of crForm.results) { + if (r instanceof RemousResults) { + return r.abscissae; + } + } + } + } + public get generatePARSimulationEnabled(): boolean { const parCalage = (this._formulaire.currentNub as Par); return ( diff --git a/src/app/components/select-section-details/select-section-details.component.html b/src/app/components/select-section-details/select-section-details.component.html new file mode 100644 index 000000000..d8917f9e5 --- /dev/null +++ b/src/app/components/select-section-details/select-section-details.component.html @@ -0,0 +1,5 @@ +<mat-select [placeholder]="uitextPlaceholder"> + <mat-option *ngFor="let p of points"> + <section-details-entry [abscissa]=p></section-details-entry> + </mat-option> +</mat-select> \ No newline at end of file diff --git a/src/app/components/select-section-details/select-section-details.component.scss b/src/app/components/select-section-details/select-section-details.component.scss new file mode 100644 index 000000000..c62ffafb0 --- /dev/null +++ b/src/app/components/select-section-details/select-section-details.component.scss @@ -0,0 +1,3 @@ +mat-select { + border: 1px solid #4dbbe9; +} diff --git a/src/app/components/select-section-details/select-section-details.component.ts b/src/app/components/select-section-details/select-section-details.component.ts new file mode 100644 index 000000000..c27db1224 --- /dev/null +++ b/src/app/components/select-section-details/select-section-details.component.ts @@ -0,0 +1,33 @@ +import { Component, Input } from '@angular/core'; + +/** + * liste déroulante de boutons de génération de formulaire "section paramétrée" + */ + +@Component({ + selector: 'select-section-details', + templateUrl: './select-section-details.component.html', + styleUrls: ['./select-section-details.component.scss'] +}) +export class SelectSectionDetailsComponent { + private _points: number[]; + + /** + * abscisses auxquelles on peut créer un formulaire "section paramétrée" + */ + @Input() + public set points(ps: number[]) { + this._points = ps; + } + + public get points(): number[] { + return this._points; + } + + constructor( + ) { } + + public get uitextPlaceholder() { + return "Générer une section paramétrée pour..."; + } +} diff --git a/src/app/results/remous-results.ts b/src/app/results/remous-results.ts index abb20aa69..aebc15e0b 100644 --- a/src/app/results/remous-results.ts +++ b/src/app/results/remous-results.ts @@ -116,6 +116,15 @@ export class RemousResults extends CalculatorResults { this._xValues.setValues(abscissae); } + /* + * abscisses pour lesquelles on a des résultats + */ + public get abscissae(): number[] { + return this._result.resultElements.map((re) => { + return re.getValue("X"); + }); + } + public update() { this._hasFlu = false; this._hasTor = false; diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts index 90095e6df..22a2956fd 100644 --- a/src/app/services/formulaire.service.ts +++ b/src/app/services/formulaire.service.ts @@ -870,13 +870,15 @@ export class FormulaireService extends Observable { const serialisedSection = sn.section.serialise(); const sectionCopy = Session.getInstance().unserialiseSingleNub(serialisedSection, false).nub; const secParam = new SectionParametree(sectionCopy as acSection); - // copy value of calculated param - const cp: ParamDefinition = sn.calculatedParam; - const scp: ParamDefinition = secParam.section.getParameter(cp.symbol); - if (cp.hasMultipleValues) { - scp.setValues(sn.result.getCalculatedValues().map(v => round(v, this.appSetupService.displayPrecision))); - } else { - scp.singleValue = sn.result.vCalc; + if (sn instanceof RegimeUniforme) { + // copy value of calculated param + const cp: ParamDefinition = sn.calculatedParam; + const scp: ParamDefinition = secParam.section.getParameter(cp.symbol); + if (cp.hasMultipleValues) { + scp.setValues(sn.result.getCalculatedValues().map(v => round(v, this.appSetupService.displayPrecision))); + } else { + scp.singleValue = sn.result.vCalc; + } } Session.getInstance().registerNub(secParam); -- GitLab