Skip to content
Snippets Groups Projects
Commit 85ccc2aa authored by francois.grand's avatar francois.grand
Browse files

- début de la calculette "section paramétrée"

- gestion des dépendances d'existence
parent 4ab802e9
No related branches found
No related tags found
No related merge requests found
Showing
with 251 additions and 41 deletions
......@@ -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>
......
......@@ -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]
......
<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
......@@ -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
......
......@@ -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();
}
}
<h1>Section paramétrée</h1>
<hydrocalc type="SectionParametree"></hydrocalc>
\ No newline at end of file
import { Component } from '@angular/core';
@Component({
selector: 'section-param',
templateUrl: "./section-param.component.html"
})
export class SectionParametreeComponent {
}
......@@ -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
......@@ -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",
......
<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
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
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"
}
......
......@@ -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));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment