diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 449c691ef62600739a325b282415ee506713cc53..ea319aa4e57f4223f57a74879c27125094e1503e 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -16,8 +16,9 @@ import { FormulaireService } from './services/formulaire/formulaire.service'; <option *ngFor="let l of intlService.languages" [value]=l.code>{{l.label}}</option> </select> - <lechapt-calmon></lechapt-calmon> + <section-param></section-param> <!-- + <lechapt-calmon></lechapt-calmon> <cond-distri></cond-distri> <select name="Language" (change)=selectLang($event)> <option *ngFor="let l of intlService.languages" [value]=l.code>{{l.label}}</option> diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e0bd258249d3ffb47103bbbd56bc273f92a0484b..7a7c38dbaab68b34b1418b02e3c36001293293fc 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -13,9 +13,11 @@ import { ParamFieldLineComponent } from './components/param-field-line/param-fie import { SelectFieldLineComponent } from './components/select-field-line/select-field-line.component'; import { CondDistriComponent } from './calculators/cond_distri/conddistri.component'; import { LechaptCalmonComponent } from './calculators/lechapt-calmon/lechaptcalmon.component'; +import { SectionParametreeComponent } from './calculators/section-param/section-param.component'; import { AlertDialog } from './components/alert-dialog/alert-dialog.component'; import { AppErrorModule } from './error.module'; import { CalculatorResultsComponent } from './components/calculator-results/calculator-results.component'; +import { SectionResultsComponent } from './components/section-results/section-results.component'; import { GenericCalculatorComponent } from './calculators/generic/calculator.component'; @NgModule({ @@ -34,9 +36,9 @@ import { GenericCalculatorComponent } from './calculators/generic/calculator.com ParamInputComponent, FieldSetComponent, ParamFieldLineComponent, SelectFieldLineComponent, - CondDistriComponent, LechaptCalmonComponent, GenericCalculatorComponent, + CondDistriComponent, LechaptCalmonComponent, SectionParametreeComponent, GenericCalculatorComponent, AlertDialog, - CalculatorResultsComponent + CalculatorResultsComponent, SectionResultsComponent ], entryComponents: [AlertDialog], bootstrap: [AppComponent] diff --git a/src/app/calculators/generic/calculator.component.html b/src/app/calculators/generic/calculator.component.html index e3b9930131d5a4a0222269c659353fee84c5ef08..8b3bd643f64e6b553df0ddc89eb16cb10af3d5a0 100644 --- a/src/app/calculators/generic/calculator.component.html +++ b/src/app/calculators/generic/calculator.component.html @@ -1,6 +1,7 @@ -<field-set *ngFor="let fs of fieldSets" [id]=fs.id [fieldSet]=fs (onRadio)=onRadioClick($event) (onSelectChange)=onSelectChanged($event)></field-set> +<field-set [style.display]="getFieldsetStyleDisplay(fs.id)" *ngFor="let fs of fieldSets" [id]=fs.id [fieldSet]=fs (onRadio)=onRadioClick($event) (onSelectChange)=onSelectChanged($event)></field-set> <div style="text-align:center;"> <button type="button" class="button_compute" name="Calculer" (click)="doCompute()" i18n="@@hyd_compute">Calculer</button> </div> -<calc-results [style.display]="getResultsStyleDisplay()"></calc-results> \ No newline at end of file +<calc-results [style.display]="getResultsStyleDisplay()"></calc-results> +<section-results [style.display]="getSectionResultsStyleDisplay()"></section-results> \ No newline at end of file diff --git a/src/app/calculators/generic/calculator.component.ts b/src/app/calculators/generic/calculator.component.ts index 8c02a02198442e7c7a0ff2e88ce034265db0f224..4ed9e585f965c24caac4b308dc2ab3cfce4ace45 100644 --- a/src/app/calculators/generic/calculator.component.ts +++ b/src/app/calculators/generic/calculator.component.ts @@ -3,13 +3,13 @@ import { Response } from '@angular/http'; import { Observable } from "rxjs/Observable"; import 'rxjs/add/operator/toPromise'; -import { IParamsEquation, Nub } from "jalhyd"; +import { IParamsEquation, ComputeNode, Nub } from "jalhyd"; import { ParamService } from '../../services/param/param.service'; import { HttpService } from '../../services/http/http.service'; import { FormulaireService } from '../../services/formulaire/formulaire.service'; import { InternationalisationService } from '../../services/internationalisation/internationalisation.service'; -import { FieldSet, FormulaireDefinition, CalculatorType, Dependency, ExistenceDependency, ValueDependency } from '../../calculators/generic/formulaire'; +import { FieldSet, SelectField, FormulaireDefinition, CalculatorType, Dependency, ExistenceDependency, ValueDependency } from '../../calculators/generic/formulaire'; import { NgParameter, ParamRadioConfig } from './ngparam'; import { CalculatorResultsComponent } from '../../components/calculator-results/calculator-results.component'; import { Observer } from '../../services/observer'; @@ -50,9 +50,14 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer { private _formulaire: FormulaireDefinition; /** - * flag d'affichage du composant de résultats + * flag d'affichage du composant de résultats fixes/variables */ - private _showResults: boolean = false; + private _showResultsFixVar: boolean = false; + + /** + * flag d'affichage du composant de résultats du calcul de section + */ + private _showResultsSection: boolean = false; constructor(private paramService: ParamService, private httpService: HttpService, private intlService: InternationalisationService, private formulaireService: FormulaireService) { this.intlService.addObserver(this); @@ -188,7 +193,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer { */ private onRadioClick(info: string) { - this._showResults = false; + this._showResultsFixVar = false; let tmp: string[] = info.split("_"); let symbol: string = tmp[0]; @@ -255,7 +260,26 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer { this.resultsComponent.addFixedResult(p, p.v, nDigits); } + private doComputeSection() { + let ssf: SelectField = <SelectField>this._formulaire.getFormulaireElementById("select_section"); + var np: [ComputeNode, IParamsEquation] = this.formulaireService.getSectionNubAndParameters(FormulaireDefinition.getSectionType(ssf.getValue())); + + let cn: ComputeNode = np[0]; + let prms: IParamsEquation = np[1]; + + let prec: number = this.getParameterValue("Pr"); // précision + let nDigits = -Math.log10(prec); + } + private doCompute() { + this._showResultsFixVar = false; + this._showResultsSection = false; + + if (this._calculatorType == CalculatorType.SectionParametree) { + this.doComputeSection(); + return; + } + let np: [Nub, IParamsEquation] = this.formulaireService.getNubAndParameters(this._calculatorType); let nub: Nub = np[0]; let prms: IParamsEquation = np[1]; @@ -263,7 +287,6 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer { let prec: number = this.getParameterValue("Pr"); // précision let nDigits = -Math.log10(prec); - this._showResults = false; let computedParam = this.getComputedParameter(); let varParam = this.getVariatedParameter(); @@ -300,11 +323,20 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer { this.resultsComponent.setGraphTitle(computedParam.symbol + " = f( " + varParam.symbol + " )"); this.resultsComponent.generateGraph(); } - this._showResults = true; + this._showResultsFixVar = true; } private getResultsStyleDisplay() { - return this._showResults ? "block" : "none"; + return this._showResultsFixVar ? "block" : "none"; + } + + private getSectionResultsStyleDisplay() { + return this._showResultsSection ? "block" : "none"; + } + + private getFieldsetStyleDisplay(id: string) { + let isDisplayed: boolean = this._formulaire.isDisplayed(id); + return isDisplayed ? "block" : "none"; } // interface Observer diff --git a/src/app/calculators/generic/formulaire.ts b/src/app/calculators/generic/formulaire.ts index 89680ccb5bdf78d9d3aba1f289350144314801e9..a8c6888130062bd6d75804bfe920ba2d48c1c1f2 100644 --- a/src/app/calculators/generic/formulaire.ts +++ b/src/app/calculators/generic/formulaire.ts @@ -5,7 +5,11 @@ import { ParamService } from '../../services/param/param.service'; import { StringMap } from '../../stringmap'; export enum CalculatorType { - ConduiteDistributrice, LechaptCalmon + ConduiteDistributrice, LechaptCalmon, SectionParametree +} + +export enum SectionType { + Trapeze, Rectangle, Cercle, Parabole } export class FormulaireDefinition { @@ -143,9 +147,9 @@ export class FormulaireDefinition { private parse_value_dependencies(json: {}, slave: FormulaireElement) { for (let di in json) { let d = json[di]; - let refField: FormulaireElement = this.getFormulaireElementById(d["refid"]); - if (refField != undefined) { - let dep = new ValueDependency(refField, slave); + let masterField: FormulaireElement = this.getFormulaireElementById(d["refid"]); + if (masterField != undefined) { + let dep = new ValueDependency(masterField, slave); dep.masterValue = d["refvalue"]; dep.slaveValue = d["value"]; this._dependencies.push(dep); @@ -156,10 +160,10 @@ export class FormulaireDefinition { private parse_existence_dependencies(json: {}, slave: FormulaireElement) { for (let di in json) { let d = json[di]; - let refField: FormulaireElement = this.getFormulaireElementById(d["refid"]); - if (refField != undefined) { - let refVal = d["refvalue"]; - let dep = new ExistenceDependency(refField, slave); + let masterField: FormulaireElement = this.getFormulaireElementById(d["refid"]); + if (masterField != undefined) { + let dep = new ExistenceDependency(masterField, slave); + dep.masterValue = d["refvalue"]; this._dependencies.push(dep); } } @@ -188,6 +192,8 @@ export class FormulaireDefinition { res.addEntry(e); } + this.parse_dependencies(res, field); + return res; } @@ -202,6 +208,8 @@ export class FormulaireDefinition { res.radioConfig = NgParameter.getRadioConfig(fieldset["option"]); res.radioState = ParamRadioConfig.FIX; res.isDefault = false; // malgré le fait qu'il soit initialisé dans la déclaration de la classe NgParam à false, quand on relit sa valeur, il vaut undefined (merci Microsoft) + + this.parse_dependencies(res, field); } return res; } @@ -217,13 +225,13 @@ export class FormulaireDefinition { let param = this.parse_input(fieldset, field); if (param != undefined) res.addField(param); - this.parse_dependencies(param, field); } else if (field["type"] === "select") { let param = this.parse_select(field); res.addField(param); - this.parse_dependencies(param, field); } } + + this.parse_dependencies(res, fieldset); } public parseConfig(config: {}) { @@ -232,7 +240,6 @@ export class FormulaireDefinition { this._defaultCalculatedParam = undefined; for (let conf_index in this._config) { - let conf = this._config[conf_index]; let conf_id: string = conf["id"]; @@ -244,9 +251,11 @@ export class FormulaireDefinition { else if (conf_id === "options") { // id du paramètre à calculer par défaut this._defaultCalculatedParam = conf["idCal"]; - let p = this.getParamFromSymbol(this._defaultCalculatedParam); - p.isDefault = true; - p.radioState = ParamRadioConfig.CAL; + if (this._defaultCalculatedParam != undefined) { + let p = this.getParamFromSymbol(this._defaultCalculatedParam); + p.isDefault = true; + p.radioState = ParamRadioConfig.CAL; + } } } } @@ -264,7 +273,11 @@ export class FormulaireDefinition { public applyDependencies() { for (let d of this.dependencies) { + let master = this.getFieldById(d.masterElement.id); if (d instanceof ExistenceDependency) { + let slave = this.getFormulaireElementById(d.slaveElement.id); + let ed = <ExistenceDependency>d; + slave.isDisplayed = master.getValue() == ed.masterValue; } else if (d instanceof ValueDependency) { let vd = <ValueDependency>d; @@ -275,7 +288,6 @@ export class FormulaireDefinition { this.setHtmlElementValue(slave, vd.slaveValue); } */ - let master = this.getFieldById(d.masterElement.id); if (master.getValue() == vd.masterValue) { let slave = this.getFieldById(d.slaveElement.id); if (this.isNumber(vd.slaveValue)) @@ -286,16 +298,38 @@ export class FormulaireDefinition { } } } + + public printDependencies() { + for (let d of this.dependencies) + console.log(d.toString()); + } + + public static getSectionType(s: string): SectionType { + if (s === "select_section_trapez") + return SectionType.Trapeze; + if (s === "select_section_rect") + return SectionType.Rectangle; + if (s === "select_section_circ") + return SectionType.Cercle; + if (s === "select_section_para") + return SectionType.Parabole; + + throw "Formulaire.getSectionType() : type de section '" + s + "' inconnu" + } + + public isDisplayed(id: string) { + return this.getFormulaireElementById(id).isDisplayed; + } } export abstract class FormulaireElement { private _id: string; - private _isDisplayed: boolean; + public isDisplayed: boolean; public label: string; constructor(id: string) { this._id = id; - this._isDisplayed = true; + this.isDisplayed = true; } get id(): string { @@ -303,6 +337,10 @@ export abstract class FormulaireElement { } public abstract updateLocalisation(loc: StringMap): void; + + public toString() { + return "id:" + this._id + (this.isDisplayed ? " displayed" : " NOT displayed") + " label:" + this.label; + } } export enum FieldType { @@ -460,10 +498,18 @@ export abstract class Dependency { public get slaveElement(): FormulaireElement { return this._slave; } + + public toString(): string { + return "master=" + this._master.toString() + "\n master val:" + this.masterValue + "\n slave=" + this._slave.toString(); + } } export class ValueDependency extends Dependency { public slaveValue: any; + + public toString() { + return "valdep\n " + super.toString() + "\n slave val " + this.slaveValue; + } } export class ExistenceDependency extends Dependency { @@ -472,4 +518,8 @@ export class ExistenceDependency extends Dependency { * false : l'élément slave est affiché si le master n'est pas affiché */ // private _direct: boolean; + + public toString() { + return "existdep\n " + super.toString(); + } } diff --git a/src/app/calculators/section-param/section-param.component.html b/src/app/calculators/section-param/section-param.component.html new file mode 100644 index 0000000000000000000000000000000000000000..25eb48d73f3da2c2d82a34a89f50dcf9c29ff25e --- /dev/null +++ b/src/app/calculators/section-param/section-param.component.html @@ -0,0 +1,2 @@ +<h1>Section paramétrée</h1> +<hydrocalc type="SectionParametree"></hydrocalc> \ No newline at end of file diff --git a/src/app/calculators/section-param/section-param.component.ts b/src/app/calculators/section-param/section-param.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..3edb7159615378aa7465b9f96ad63adba9786776 --- /dev/null +++ b/src/app/calculators/section-param/section-param.component.ts @@ -0,0 +1,8 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'section-param', + templateUrl: "./section-param.component.html" +}) +export class SectionParametreeComponent { +} diff --git a/src/app/calculators/section-param/section-param.config.json b/src/app/calculators/section-param/section-param.config.json index 446fabc36a297343e1cd818843892a1baffd1a38..7ddbdd3d4ed7316aeb4771a22be7bdf695b9219e 100644 --- a/src/app/calculators/section-param/section-param.config.json +++ b/src/app/calculators/section-param/section-param.config.json @@ -100,7 +100,7 @@ }, { "type": "input", - "id": "B", + "id": "LargeurBerge", "unit": "m", "value": 2 } @@ -161,7 +161,6 @@ ] }, { - "id": "options", - "idCal": "J" + "id": "options" } ] \ No newline at end of file diff --git a/src/app/calculators/section-param/section-param.fr.json b/src/app/calculators/section-param/section-param.fr.json index 213c48f6fd04e3507f2eb0c44acd643ad2c04f53..46c2358d149b747d35a3188fef12cb04d9171dfa 100644 --- a/src/app/calculators/section-param/section-param.fr.json +++ b/src/app/calculators/section-param/section-param.fr.json @@ -13,7 +13,7 @@ "D": "Diamètre", "fs_section_para": "Définition de la section parabolique", "k": "Coefficient", - "B": "Largeur de berge", + "LargeurBerge": "Largeur au niveau des berges", "fs_bief": "Caractéristiques du bief", "K": "Coefficient de Strickler", "If": "Pente du fond", diff --git a/src/app/components/section-results/section-results.component.html b/src/app/components/section-results/section-results.component.html new file mode 100644 index 0000000000000000000000000000000000000000..2eeea69a6313c7469aed95d613352a7aeeb0b90f --- /dev/null +++ b/src/app/components/section-results/section-results.component.html @@ -0,0 +1,8 @@ +<div style="text-align:center;"> + <table style="float: left"> + <tr *ngFor="let r of _results; let i=index" [class]="getResultClass(i)"> + <td class="result_label">{{r.label}}</td> + <td class="result_value">{{r.value}}</td> + </tr> + </table> +</div> \ No newline at end of file diff --git a/src/app/components/section-results/section-results.component.ts b/src/app/components/section-results/section-results.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..812a0e9d97ff3dd8495b54668af0ed94d9bd171c --- /dev/null +++ b/src/app/components/section-results/section-results.component.ts @@ -0,0 +1,39 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'section-results', + templateUrl: './section-results.component.html', + styles: [` + .result_label { + text-align: right; + padding-top:10px; + padding-bottom:10px; + padding-right:10px; + } + .result_value { + text-align: center; + padding-left:30px; + padding-right:30px; + } + .result_id_0 { + background-color: #f0f0f0; + } + .result_id_2 { + font-weight: bold; + } + ` + ] +}) +export class SectionResultsComponent { + /** + * résultats + */ + private _results: Object[] = []; + + private getFixedResultClass(i: number) { + // if (this.getVariatedParameter() == undefined && i == this._fixedResults.length - 1) + if (i == this._results.length - 1) + return "result_id_2" + return "result_id_" + String(i & 1); + } +} \ No newline at end of file diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 90925ed388a864e46b433c9d7a0720f7d3d7f411..53721fff6e54b379e1eb0d77f54d7bb5ee0f8c25 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -1,11 +1,14 @@ import { Injectable } from '@angular/core'; import { Response } from '@angular/http'; -import { IParamsEquation, Nub, ConduiteDistrib, ConduiteDistribParams, LechaptCalmon, LechaptCalmonParams } from "jalhyd"; +import { IParamsEquation, ComputeNode, Nub, ConduiteDistrib, ConduiteDistribParams } from "jalhyd"; +import { LechaptCalmon, LechaptCalmonParams, ParamsSectionTrapez, cSnTrapez } from "jalhyd"; +import { ParamsSectionRectang, cSnRectang, ParamsSectionCirc, cSnCirc, ParamsSectionPuiss, cSnPuiss } from "jalhyd"; + import { ParamService } from '../param/param.service'; import { HttpService } from '../../services/http/http.service'; -import { FormulaireDefinition, FormulaireElement, CalculatorType, SelectField } from '../../calculators/generic/formulaire'; +import { FormulaireDefinition, FormulaireElement, CalculatorType, SectionType, SelectField } from '../../calculators/generic/formulaire'; import { StringMap } from '../../stringmap'; @Injectable() @@ -112,6 +115,56 @@ export class FormulaireService { } } + public getSectionNubAndParameters(st: SectionType): [ComputeNode, IParamsEquation] { + let f = this.getFormulaire(CalculatorType.SectionParametree); + + // bief + let Ks = f.getParameterValue("Ks");; // Strickler + let If: number = f.getParameterValue("If"); // Pente du fond + let YB: number = f.getParameterValue("YB"); // Hauteur de berge + + // caractéristiques hydro + let Q: number = f.getParameterValue("Q"); // débit Q + let Y: number = f.getParameterValue("Y"); // tirant d'eau + + let Prec = f.getParameterValue("prec"); // précision calcul/affichage + + // ?? + // let YCL: number = f.getParameterValue("YCL"); // Condition limite en cote à l'amont ou à l'aval + // let Dx: number = f.getParameterValue("Dx"); // Pas d'espace (positif en partant de l'aval, négatif en partant de l'amont) + // let Long: number = f.getParameterValue("Long"); // Longueur du bief + + switch (st) { + case SectionType.Trapeze: + { + let LargeurFond = f.getParameterValue("LargeurFond"); // Largeur au fond + let Fruit = f.getParameterValue("Fruit"); // Fruit des berges + let prms = new ParamsSectionTrapez(LargeurFond, Fruit, Y, Ks, Q, If, Prec, YB); + let cn = new cSnTrapez(undefined, prms); + return [cn, prms]; + } + + case SectionType.Rectangle: + { + let LargeurFond = f.getParameterValue("LargeurFond"); // Largeur au fond + let prms = new ParamsSectionRectang(Y, LargeurFond, Ks, Q, If, Prec, YB); + let cn = new cSnRectang(undefined, prms); + return [cn, prms]; + } + + case SectionType.Cercle: + { + let D = f.getParameterValue("D"); // Largeur au fond + let prms = new ParamsSectionCirc(D, Y, Ks, Q, If, Prec, YB); + let cn = new cSnCirc(undefined, prms); + return [cn, prms]; + } + + default: + throw "FormulaireService.getNubAndParameters() : valeur de SectionType " + st + " non implémentée" + } + } + public getConfigPathPrefix(ct: CalculatorType): string { if (ct == undefined) throw "FormulaireService.getConfigPathPrefix() : invalid undefined CalculatorType" @@ -123,6 +176,9 @@ export class FormulaireService { case CalculatorType.LechaptCalmon: return "app/calculators/lechapt-calmon/lechapt-calmon."; + case CalculatorType.SectionParametree: + return "app/calculators/section-param/section-param."; + default: throw "FormulaireService.getConfigPathPrefix() : valeur de CalculatorType " + ct + " non implémentée" } diff --git a/src/app/services/param/param.service.ts b/src/app/services/param/param.service.ts index 64ca6dfe9aea3c058d78570a65f3ee501fa4637d..eefef0c0741dda3341eca0394046fb881a8808aa 100644 --- a/src/app/services/param/param.service.ts +++ b/src/app/services/param/param.service.ts @@ -16,13 +16,17 @@ export class ParamService { this.addParameters("cond_distri"); this.addParameters("lechapt_calmon"); + this.addParameters("section_param_trapez"); + this.addParameters("section_param_rect"); + this.addParameters("section_param_circ"); + this.addParameters("section_param_para"); } private hasParameter(symbol: string): boolean { - for (let p of this._params) { + for (let p of this._params) if (p.symbol === symbol) return true; - } + return false; } @@ -39,9 +43,17 @@ export class ParamService { if (!this.hasParameter(p.symbol)) this._params.push(p); */ - let p: ParamDefinition = cdp[pi]; - if (!this.hasParameter(p.symbol)) - this._params.push(new NgParameter(p)); + /* + ce code ne marche pas mais compile sans pb !! + + let p: ParamDefinition = cdp[pi]; // on peut avoir n'importe quoi dans p malgré son typage + if (!this.hasParameter(p.symbol)) + this._params.push(new NgParameter(p)); + */ + let p = cdp[pi]; + if (p instanceof ParamDefinition) // obligatoire car malgré le typage de p, p peut être = constructor ou n'importe quel autre membre + if (!this.hasParameter(p.symbol)) + this._params.push(new NgParameter(p)); } }