From af0d46a062dad84c235ec8e6d660ffc8b15d2813 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Wed, 30 Oct 2019 16:04:46 +0100 Subject: [PATCH] interface for module Trigo --- e2e/calculate-all-params.e2e-spec.ts | 2 +- e2e/check-translations.e2e-spec.ts | 2 +- e2e/clone-all-calc.e2e-spec.ts | 2 +- src/app/calculators/trigo/trigo.config.json | 32 +++++++++++ src/app/calculators/trigo/trigo.en.json | 20 +++++++ src/app/calculators/trigo/trigo.fr.json | 20 +++++++ .../definition/concrete/form-trigo.ts | 53 +++++++++++++++++++ src/app/formulaire/fieldset.ts | 16 ++++++ src/app/formulaire/select-field.ts | 16 ++++-- src/app/services/formulaire.service.ts | 1 + src/locale/messages.en.json | 6 ++- src/locale/messages.fr.json | 6 ++- 12 files changed, 166 insertions(+), 10 deletions(-) create mode 100644 src/app/calculators/trigo/trigo.config.json create mode 100644 src/app/calculators/trigo/trigo.en.json create mode 100644 src/app/calculators/trigo/trigo.fr.json create mode 100644 src/app/formulaire/definition/concrete/form-trigo.ts diff --git a/e2e/calculate-all-params.e2e-spec.ts b/e2e/calculate-all-params.e2e-spec.ts index dcbd5b7c3..ace899e9e 100644 --- a/e2e/calculate-all-params.e2e-spec.ts +++ b/e2e/calculate-all-params.e2e-spec.ts @@ -23,7 +23,7 @@ describe("ngHyd − calculate all parameters of all calculators", () => { 11, 12, 13, 15, 17, 18, 19, 20, 21, // 22 - Solveur is not calculated here because it is not independent - 23 + 23, 24 ]; // for each calculator diff --git a/e2e/check-translations.e2e-spec.ts b/e2e/check-translations.e2e-spec.ts index d8491b8d9..40799429f 100644 --- a/e2e/check-translations.e2e-spec.ts +++ b/e2e/check-translations.e2e-spec.ts @@ -25,7 +25,7 @@ describe("ngHyd − check translation of all calculators", () => { }); // get calculators list (IDs) @TODO read it from config, but can't import jalhyd here :/ - const calcTypes = [ 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23 ]; + const calcTypes = [ 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 15, 17, 18, 19, 20, 21, 22, 23, 24 ]; // options of "Language" selector on preferences page const langs = [ "English", "Français" ]; diff --git a/e2e/clone-all-calc.e2e-spec.ts b/e2e/clone-all-calc.e2e-spec.ts index 1f0ba7fcb..4f0b7c3d4 100644 --- a/e2e/clone-all-calc.e2e-spec.ts +++ b/e2e/clone-all-calc.e2e-spec.ts @@ -23,7 +23,7 @@ describe("ngHyd − clone all calculators with all possible <select> values", () 11, 12, 13, 15, 17, 18, 19, 20, 21, // 22 - Solveur is not cloned here because it is not independent - 23 + 23, 24 ]; // for each calculator diff --git a/src/app/calculators/trigo/trigo.config.json b/src/app/calculators/trigo/trigo.config.json new file mode 100644 index 000000000..6dbb51a8c --- /dev/null +++ b/src/app/calculators/trigo/trigo.config.json @@ -0,0 +1,32 @@ +[ + { + "id": "fs_trigo", + "type": "fieldset", + "defaultOperation": "COS", + "defaultUnit": "DEG", + "fields": [ + { + "id": "select_operation", + "type": "select", + "source": "trigo_operation" + }, + { + "id": "select_unit", + "type": "select", + "source": "trigo_unit" + } + ] + }, + { + "id": "fs_params", + "type": "fieldset", + "fields": [ "X", "Y" ] + }, + { + "type": "options", + "idCal": "Y", + "operationSelectId": "select_operation", + "unitSelectId": "select_unit", + "_help": "util/trigo.html" + } +] \ No newline at end of file diff --git a/src/app/calculators/trigo/trigo.en.json b/src/app/calculators/trigo/trigo.en.json new file mode 100644 index 000000000..9208d6dca --- /dev/null +++ b/src/app/calculators/trigo/trigo.en.json @@ -0,0 +1,20 @@ +{ + "fs_trigo": "Trigonometric parameters", + + "select_operation": "Operation", + "select_operation_0": "cos", + "select_operation_1": "sin", + "select_operation_2": "tan", + "select_operation_3": "cosh", + "select_operation_4": "sinh", + "select_operation_5": "tanh", + + "select_unit": "Unit", + "select_unit_0": "Degrees", + "select_unit_1": "Radians", + + "fs_params": "Equation parameters", + + "X": "X", + "Y": "Y" +} \ No newline at end of file diff --git a/src/app/calculators/trigo/trigo.fr.json b/src/app/calculators/trigo/trigo.fr.json new file mode 100644 index 000000000..15c5a8a4e --- /dev/null +++ b/src/app/calculators/trigo/trigo.fr.json @@ -0,0 +1,20 @@ +{ + "fs_trigo": "Paramètres trigonométriques", + + "select_operation": "Opération", + "select_operation_0": "cos", + "select_operation_1": "sin", + "select_operation_2": "tan", + "select_operation_3": "cosh", + "select_operation_4": "sinh", + "select_operation_5": "tanh", + + "select_unit": "Unité", + "select_unit_0": "Degrés", + "select_unit_1": "Radians", + + "fs_params": "Paramètres de l'équation", + + "X": "X", + "Y": "Y" +} \ No newline at end of file diff --git a/src/app/formulaire/definition/concrete/form-trigo.ts b/src/app/formulaire/definition/concrete/form-trigo.ts new file mode 100644 index 000000000..510f8b3c9 --- /dev/null +++ b/src/app/formulaire/definition/concrete/form-trigo.ts @@ -0,0 +1,53 @@ +import { IObservable } from "jalhyd"; + +import { FormulaireBase } from "./form-base"; +import { FieldSet } from "../../fieldset"; +import { FormResultFixedVar } from "../form-result-fixedvar"; + +/** + * Formulaire pour les fonctions trigonométriques + */ +export class FormulaireTrigo extends FormulaireBase { + + /** id of select configuring operation */ + private _operationSelectId: string; + + /** id of select configuring unit */ + private _unitSelectId: string; + + protected parseOptions(json: {}) { + super.parseOptions(json); + this._operationSelectId = this.getOption(json, "operationSelectId"); + this._unitSelectId = this.getOption(json, "unitSelectId"); + } + + public afterParseFieldset(fs: FieldSet) { + if (this._operationSelectId) { + const sel = fs.getFormulaireNodeById(this._operationSelectId); + if (sel) { + fs.properties.addObserver(this); + } + } + if (this._unitSelectId) { + const sel = fs.getFormulaireNodeById(this._unitSelectId); + if (sel) { + fs.properties.addObserver(this); + } + } + } + + // interface Observer + + public update(sender: IObservable, data: any) { + super.update(sender, data); + if (data.action === "propertyChange") { + /* if (data.name === "gridType") { + this.reset(); + // Inclined grids have more input fields (OEntH and cIncl) + this.getFieldsetById("fs_grille").updateFields(); + // Alpha and Beta are not always shown + this.getFieldsetById("fs_plan").updateFields(); + } */ + } + } +} diff --git a/src/app/formulaire/fieldset.ts b/src/app/formulaire/fieldset.ts index 068116458..cca4508d6 100644 --- a/src/app/formulaire/fieldset.ts +++ b/src/app/formulaire/fieldset.ts @@ -11,6 +11,8 @@ import { GrilleProfile, BiefRegime, Solveur, + TrigoOperation, + TrigoUnit, } from "jalhyd"; import { FormulaireElement } from "./formulaire-element"; @@ -288,6 +290,11 @@ export class FieldSet extends FormulaireElement implements Observer { case "fs_water_line": // Bief this.setSelectValueFromProperty("select_regime", "regime"); break; + + case "fs_trigo": // Trigo + this.setSelectValueFromProperty("select_operation", "trigoOperation"); + this.setSelectValueFromProperty("select_unit", "trigoUnit"); + break; } } @@ -351,6 +358,8 @@ export class FieldSet extends FormulaireElement implements Observer { this.setPropertyValueFromConfig(json, "defaultGridType", "gridType", GrilleType); this.setPropertyValueFromConfig(json, "defaultRegime", "regime", BiefRegime); this.setPropertyValueFromConfig(json, "varCalc", "varCalc"); + this.setPropertyValueFromConfig(json, "defaultOperation", "trigoOperation", TrigoOperation); + this.setPropertyValueFromConfig(json, "defaultUnit", "trigoUnit", TrigoUnit); this.updateFields(); } @@ -402,6 +411,7 @@ export class FieldSet extends FormulaireElement implements Observer { switch (data.action) { case "select": const senderId: string = sender.id.replace(/\d+$/, ""); + console.log("fieldset.update()", sender.constructor.name, data); switch (senderId) { case "select_section": // sections paramétrées, courbes de remous, régimes uniformes // "nodeType" is a property of the section child, not of the parent @@ -442,6 +452,12 @@ export class FieldSet extends FormulaireElement implements Observer { case "select_regime": // Bief this.setPropValue("regime", data.value.value); break; + case "select_operation": // Trigo + this.setPropValue("trigoOperation", data.value.value); + break; + case "select_unit": // Trigo + this.setPropValue("trigoUnit", data.value.value); + break; } break; } diff --git a/src/app/formulaire/select-field.ts b/src/app/formulaire/select-field.ts index b2ea54a8c..174fc258c 100644 --- a/src/app/formulaire/select-field.ts +++ b/src/app/formulaire/select-field.ts @@ -9,9 +9,8 @@ import { LoiDebit, GrilleType, GrilleProfile, - Solveur, - ParamValueMode, - Session + TrigoUnit, + TrigoOperation } from "jalhyd"; import { Field } from "./field"; @@ -198,6 +197,17 @@ export class SelectField extends Field { this.addEntry(new SelectEntry(this._entriesBaseId + BiefRegime.Fluvial, BiefRegime.Fluvial)); this.addEntry(new SelectEntry(this._entriesBaseId + BiefRegime.Torrentiel, BiefRegime.Torrentiel)); break; + + case "trigo_operation": // Trigo: opération (cos, sin…) + for (let j = 0; j < Object.keys(TrigoOperation).length / 2; j++) { + this.addEntry(new SelectEntry(this._entriesBaseId + j, j)); + } + break; + + case "trigo_unit": // Trigo: unité (degrés, radians) + this.addEntry(new SelectEntry(this._entriesBaseId + TrigoUnit.DEG, TrigoUnit.DEG)); + this.addEntry(new SelectEntry(this._entriesBaseId + TrigoUnit.RAD, TrigoUnit.RAD)); + break; } this.afterParseConfig(); diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts index d8b6d13f8..416056c4d 100644 --- a/src/app/services/formulaire.service.ts +++ b/src/app/services/formulaire.service.ts @@ -87,6 +87,7 @@ export class FormulaireService extends Observable { this.calculatorPaths[CalculatorType.Bief] = "bief"; this.calculatorPaths[CalculatorType.Solveur] = "solveur"; this.calculatorPaths[CalculatorType.YAXB] = "yaxb"; + this.calculatorPaths[CalculatorType.Trigo] = "trigo"; } private get _intlService(): I18nService { diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index 4d329f2cb..8b45f7600 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -467,8 +467,10 @@ "INFO_EXAMPLE_LABEL_PAB_COMPLETE": "Standard fish ladder", "INFO_EXAMPLES_TITLE": "Examples", "INFO_EXAMPLES_SUBTITLE": "Load standard examples", - "INFO_YAXB_TITRE": "Y = A.X + B", - "INFO_YAXB_TITRE_COURT": "Y=A.X+B", + "INFO_YAXB_TITRE": "Linear function", + "INFO_YAXB_TITRE_COURT": "Linear f.", + "INFO_TRIGO_TITRE": "Trigonometric function", + "INFO_TRIGO_TITRE_COURT": "Trigo. f.", "WARNING_WARNINGS_ABSTRACT": "%nb% warnings occurred during calculation", "WARNING_REMOUS_ARRET_CRITIQUE": "Calculation stopped: critical elevation reached at abscissa %x%", "WARNING_STRUCTUREKIVI_HP_TROP_ELEVE": "h/p must not be greater than 2.5. h/p is forced to 2.5", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index c4ab404cf..4ae53cad4 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -466,8 +466,10 @@ "INFO_EXAMPLE_LABEL_PAB_COMPLETE": "Passe à bassins type", "INFO_EXAMPLES_TITLE": "Exemples", "INFO_EXAMPLES_SUBTITLE": "Charger des exemples types", - "INFO_YAXB_TITRE": "Y = A.X + B", - "INFO_YAXB_TITRE_COURT": "Y=A.X+B", + "INFO_YAXB_TITRE": "Fonction affine", + "INFO_YAXB_TITRE_COURT": "F. affine", + "INFO_TRIGO_TITRE": "Fonction trigonométrique", + "INFO_TRIGO_TITRE_COURT": "F. trigo.", "WARNING_WARNINGS_ABSTRACT": "%nb% avertissements rencontrés lors du calcul", "WARNING_REMOUS_ARRET_CRITIQUE": "Arrêt du calcul : hauteur critique atteinte à l'abscisse %x%", "WARNING_STRUCTUREKIVI_HP_TROP_ELEVE": "h/p ne doit pas être supérieur à 2,5. h/p est forcé à 2,5", -- GitLab