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

section paramétrée : implémentation de l'affichage des paramètres variables

parent bccba9cd
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,7 @@ 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, SelectField, FormulaireDefinition, CalculatorType, Dependency, ExistenceDependency, ValueDependency } from '../../calculators/generic/formulaire';
import { FieldSet, InputField, 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 { SectionResultsComponent } from '../../components/section-results/section-results.component';
......@@ -246,6 +246,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer {
// this.appRef.tick();
// this.changeDetectorRef.detectChanges(); // provoque une détection des changements dans les contrôles
this.resultsComponent.reset(false);
this.applyDependencies();
}
......@@ -265,19 +266,98 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer {
return this._formulaire.getParamFromState(ParamRadioConfig.VAR);
}
private addFixedResults(nDigits: number) {
private isMySectionType(nodeType: ComputeNodeType, strict: boolean) {
let res: boolean = nodeType == this._nodeType;
if (strict)
return res;
return res || nodeType == ComputeNodeType.SectionParametree
}
private getSectionVariatedParameter(): NgParameter {
let res: NgParameter = this._formulaire.getParamFromState(ParamRadioConfig.VAR);
if (res != undefined && this.isMySectionType(res.computeNodeType, false))
return res;
return undefined;
}
private addFixedResults(nDigits: number, displaySymbol: boolean) {
for (let p of this._formulaire.getInputParameters())
if (p.radioState == ParamRadioConfig.FIX && p.symbol !== "Pr")
this.resultsComponent.addFixedResult(p, p.getValue(), nDigits);
this.resultsComponent.addFixedResult(p, p.getValue(), nDigits, displaySymbol);
}
private addSectionFixedResults(nDigits: number, displaySymbol: boolean) {
for (let p of this._formulaire.getDisplayedInputParameters())
if (p.radioState == ParamRadioConfig.FIX && this.isMySectionType(p.computeNodeType, false) && p.symbol !== "Pr")
this.resultsComponent.addFixedResult(p, p.getValue(), nDigits, displaySymbol);
}
private addSectionFixedResult(val: number, label: string, nDigits: number, drawLabel: string = undefined) {
this.sectionResultsComponent.addResult(val, label, nDigits, drawLabel);
}
private getSectionComputedParam(): { symbol: string, label: string } {
let targetSelect: SelectField = <SelectField>this._formulaire.getFieldById("select_target");
let targetValue: string = targetSelect.getValue();
let prefix = "select_target_"
let l = prefix.length;
let symbol: string = targetValue.substr(l, targetValue.length - l);
let label = targetSelect.getLabel();
return { symbol, label };
}
private doComputeSectionVar(varParam: NgParameter) {
let prec: number = this.getParameterValue("Pr"); // précision
let nDigits = -Math.log10(prec);
this.resultsComponent.reset(false);
this.addSectionFixedResults(nDigits, false);
let computedParam = this.getSectionComputedParam();
this.resultsComponent.setVariableParamHeaderFromParameter(varParam, false);
this.resultsComponent.setVariableResultHeader(computedParam["label"]);
let ssf: SelectField = <SelectField>this._formulaire.getFormulaireElementById("select_section");
let typeSect: ComputeNodeType = FormulaireDefinition.getSectionType(ssf.getValue());
var np: [acSection, IParamsEquation] = this.formulaireService.getSectionNubAndParameters(typeSect);
let sect: acSection = np[0];
let prms: IParamsEquation = np[1];
let min: number = +varParam.minValue;
let max: number = +varParam.maxValue;
let step: number = +varParam.stepValue;
let yField: InputField = <InputField>this._formulaire.getFormulaireElementById("Y");
let Y: number = yField.getValue();
let compSymbol = computedParam["symbol"];
for (let val = min; val <= max; val += step) {
prms[varParam.symbol].v = val;
sect.Reset(true);
let res = sect.Calc(compSymbol, Y);
this.resultsComponent.addVarResult(val, res, nDigits);
}
this.resultsComponent.setGraphTitle(computedParam.symbol + " = f( " + varParam.symbol + " )");
this.resultsComponent.generateGraph();
this._showResultsFixVar = true;
}
private doComputeSection() {
this.sectionResultsComponent.reset();
let varParam = this.getSectionVariatedParameter();
if (varParam != undefined) {
this.doComputeSectionVar(varParam);
return;
}
let ssf: SelectField = <SelectField>this._formulaire.getFormulaireElementById("select_section");
let typeSect: ComputeNodeType = FormulaireDefinition.getSectionType(ssf.getValue());
var np: [acSection, IParamsEquation] = this.formulaireService.getSectionNubAndParameters(typeSect);
......@@ -376,26 +456,26 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer {
let prms: IParamsEquation = np[1];
let prec: number = this.getParameterValue("Pr"); // précision
let nDigits = -Math.log10(prec);
let nDigits: number = -Math.log10(prec);
let computedParam = this.getComputedParameter();
let computedParam: NgParameter = this.getComputedParameter();
let varParam = this.getVariatedParameter();
let varParam: NgParameter = this.getVariatedParameter();
this.resultsComponent.reset(varParam == undefined);
if (varParam == undefined) {
// pas de paramètre à varier
let res = nub.Calc(computedParam.symbol, 0, prec).vCalc;
this.addFixedResults(nDigits);
this.resultsComponent.addFixedResult(computedParam, res, nDigits);
this.addFixedResults(nDigits, true);
this.resultsComponent.addFixedResult(computedParam, res, nDigits, true);
}
else {
// il y a un paramètre à varier
this.addFixedResults(nDigits);
this.resultsComponent.setVariableParamHeader(varParam);
this.resultsComponent.setVariableResultHeader(computedParam);
this.addFixedResults(nDigits, true);
this.resultsComponent.setVariableParamHeaderFromParameter(varParam, true);
this.resultsComponent.setVariableResultHeaderFromParameter(computedParam);
let min: number = +varParam.minValue;
let max: number = +varParam.maxValue;
......@@ -470,6 +550,8 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, Observer {
* réception d'un événement d'un select
*/
private onSelectChanged(val: string) {
this.resultsComponent.reset(false);
this.sectionResultsComponent.reset();
this.updateSectionType(val);
this.applyDependencies();
}
......
......@@ -111,6 +111,16 @@ export class FormulaireDefinition {
return res;
}
public getDisplayedInputParameters(): NgParameter[] {
let res = [];
for (let fs of this._fieldSets)
if (fs.isDisplayed)
for (let p of fs.fields)
if (p instanceof NgParameter && p.isDisplayed)
res.push(p);
return res;
}
public getNodeParameterValue(nodeType: ComputeNodeType, symbol: string): number {
for (let fs of this._fieldSets) {
for (let p of fs.fields) {
......@@ -546,6 +556,12 @@ export class SelectField extends Field {
}
}
public getLabel() {
if (this.selectedEntry == undefined)
return undefined;
return this.selectedEntry.label;
}
protected verifyDependency(d: Dependency): boolean {
switch (d.masterCondition.type) {
case DependencyConditionType.HasValue:
......
......@@ -214,55 +214,55 @@
"type": "select",
"select": [
{
"id": "select_target_hs"
"id": "select_target_Hs"
},
{
"id": "select_target_hsc"
"id": "select_target_Hsc"
},
{
"id": "select_target_b"
"id": "select_target_B"
},
{
"id": "select_target_p"
"id": "select_target_P"
},
{
"id": "select_target_s"
"id": "select_target_S"
},
{
"id": "select_target_r"
"id": "select_target_R"
},
{
"id": "select_target_v"
"id": "select_target_V"
},
{
"id": "select_target_fr"
"id": "select_target_Fr"
},
{
"id": "select_target_yc"
"id": "select_target_Yc"
},
{
"id": "select_target_yn"
"id": "select_target_Yn"
},
{
"id": "select_target_yf"
"id": "select_target_Yf"
},
{
"id": "select_target_yt"
"id": "select_target_Yt"
},
{
"id": "select_target_yco"
"id": "select_target_Yco"
},
{
"id": "select_target_j"
"id": "select_target_J"
},
{
"id": "select_target_i_j"
"id": "select_target_I-J"
},
{
"id": "select_target_imp"
"id": "select_target_Imp"
},
{
"id": "select_target_tau0"
"id": "select_target_Tau0"
}
]
}
......
......@@ -25,21 +25,21 @@
"Pr": "Précision de calcul",
"fs_computed_var": "Donnée à calculer",
"select_target": "Choix de la donnée à calculer",
"select_target_hs": "La charge spécifique (m)",
"select_target_hsc": "La charge critique (m)",
"select_target_b": "La largeur au miroir (m)",
"select_target_p": "Le périmètre mouillé (m)",
"select_target_s": "La surface mouillée (m2)",
"select_target_r": "Le rayon hydraulique (m)",
"select_target_v": "La vitesse moyenne (m/s)",
"select_target_fr": "Le Froude",
"select_target_yc": "Le tirant d'eau critique (m)",
"select_target_yn": "Le tirant d'eau normal (m)",
"select_target_yf": "Le tirant d'eau fluvial (m)",
"select_target_yt": "Le tirant d'eau torrentiel (m)",
"select_target_yco": "Le tirant d'eau conjugué (m)",
"select_target_j": "La perte de charge (m)",
"select_target_i_j": "Variation linéaire de l'énergie spécifique (m/m)",
"select_target_imp": "Impulsion (m/m)",
"select_target_tau0": "La force tractrice (N)"
"select_target_Hs": "La charge spécifique (m)",
"select_target_Hsc": "La charge critique (m)",
"select_target_B": "La largeur au miroir (m)",
"select_target_P": "Le périmètre mouillé (m)",
"select_target_S": "La surface mouillée (m2)",
"select_target_R": "Le rayon hydraulique (m)",
"select_target_V": "La vitesse moyenne (m/s)",
"select_target_Fr": "Le Froude",
"select_target_Yc": "Le tirant d'eau critique (m)",
"select_target_Yn": "Le tirant d'eau normal (m)",
"select_target_Yf": "Le tirant d'eau fluvial (m)",
"select_target_Yt": "Le tirant d'eau torrentiel (m)",
"select_target_Yco": "Le tirant d'eau conjugué (m)",
"select_target_J": "La perte de charge (m)",
"select_target_I-J": "Variation linéaire de l'énergie spécifique (m/m)",
"select_target_Imp": "Impulsion (m/m)",
"select_target_Tau0": "La force tractrice (N)"
}
\ No newline at end of file
......@@ -32,18 +32,11 @@ export class CalculatorResultsComponent {
*/
private _isFixed: boolean;
/**
* affichage de la table des résultats non variés
*/
// private _showFixedResults: boolean = false;
private _fixedResults: Object[] = [];
/**
* affichage de la table des résultats variés
* affichage de la table des résultats variés
*/
// private _showVarResults: boolean = false;
private get showVarResults(): boolean {
return this._varResults.length > 0;
}
......@@ -52,8 +45,16 @@ export class CalculatorResultsComponent {
private _variableResultHeader: string;
/**
* tableau de valeurs de la table des résultats variés
*/
private _varResults: Object[] = [];
/**
* tableau de valeurs du graphe des résultats variés
*/
private _varGraph: number[] = [];
/*
* config du graphe
*/
......@@ -74,21 +75,22 @@ export class CalculatorResultsComponent {
}
};
public addFixedResult(p: NgParameter, v: number, fixedPrec: number) {
this._fixedResults.push({ "label": this.paramLabel(p), "value": v.toFixed(fixedPrec) });
public addFixedResult(p: NgParameter, v: number, fixedPrec: number, displaySymbol: boolean) {
this._fixedResults.push({ "label": this.paramLabel(p, displaySymbol), "value": v.toFixed(fixedPrec) });
}
public addVarResult(paramVal: number, resVal: number, fixedPrec: number) {
this._varResults.push({ "param": paramVal.toFixed(fixedPrec), "result": resVal.toFixed(fixedPrec) });
this._varGraph.push(resVal);
}
public generateGraph() {
let labs = [];
let dat = [];
for (let r of this._varResults) {
for (let i in this._varResults) {
let r = this._varResults[i];
labs.push(r["param"]);
dat.push(r["result"]);
dat.push(this._varGraph[i]);
}
this.graph_data = {
......@@ -104,45 +106,49 @@ export class CalculatorResultsComponent {
public reset(fixed: boolean) {
this._isFixed = fixed;
// this._showFixedResults = false;
// this._showVarResults = false;
this._fixedResults = [];
this._varResults = [];
this._varGraph = [];
this._variableParamHeader = undefined;
this._variableResultHeader = undefined;
this.graph_options.title.text = undefined;
}
public setVariableParamHeader(p: NgParameter) {
this._variableParamHeader = this.paramLabel(p);
public setVariableParamHeader(h: string) {
this._variableParamHeader = h;
}
public setVariableParamHeaderFromParameter(p: NgParameter, displaySymbol: boolean) {
this._variableParamHeader = this.paramLabel(p, displaySymbol);
}
public setVariableResultHeader(p: NgParameter) {
this._variableResultHeader = this.paramLabel(p);
public setVariableResultHeader(h: string) {
this._variableResultHeader = h;
}
public setVariableResultHeaderFromParameter(p: NgParameter) {
this._variableResultHeader = this.paramLabel(p, true);
}
public setGraphTitle(t: string) {
this.graph_options.title.text = t;
}
private paramLabel(p: NgParameter): string {
let res = p.symbol;
if (p.label != undefined && p.label != "")
res += ": " + p.label;
private paramLabel(p: NgParameter, displaySymbol: boolean): string {
let res = "";
if (displaySymbol)
res += p.symbol;
if (p.label != undefined && p.label != "") {
if (res.length > 0)
res += ":";
res += p.label;
}
if (p.unit != undefined && p.unit != "")
res += " (" + p.unit + ")";
return res;
}
// public show() {
// if (this._varResults.length > 0)
// this._showVarResults = true;
// else
// this._showFixedResults = true;
// }
private getFixedResultClass(i: number) {
// if (this.getVariatedParameter() == undefined && i == this._fixedResults.length - 1)
if (this._isFixed && i == this._fixedResults.length - 1)
return "result_id_2"
return "result_id_" + String(i & 1);
......
......@@ -51,6 +51,7 @@ export class SectionCanvasComponent {
public reset() {
this._section = undefined;
this._levels = [];
this._calcCanvas.clear();
}
private computeScale(maxWidth: number, maxHeight: number) {
......
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