Commit 847dc945 authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

Fix #353 - merge Formulaire classes

parent 8be6cb96
import { Component, Input, Output, EventEmitter, OnChanges, OnDestroy } from "@angular/core";
import { NgParameter } from "../../formulaire/ngparam";
import { NgParameter } from "../../formulaire/elements/ngparam";
import { LinkedValue, ParamValueMode, Observer, Structure, acSection, ParamDefinition, ChildNub } from "jalhyd";
import { FormulaireService } from "../../services/formulaire.service";
import { I18nService } from "../../services/internationalisation.service";
......
import { Component, Input, AfterViewInit, Output, EventEmitter } from "@angular/core";
import { NgParameter } from "../../formulaire/ngparam";
import { NgParameter } from "../../formulaire/elements/ngparam";
import { DialogEditParamValuesComponent } from "../dialog-edit-param-values/dialog-edit-param-values.component";
import { MatDialog } from "@angular/material";
import { ParamValueMode, Observer, Structure } from "jalhyd";
......
import { Component, Input, OnInit } from "@angular/core";
import { SelectField } from "../../formulaire/select-field";
import { SelectEntry } from "../../formulaire/select-entry";
import { SelectField } from "../../formulaire/elements/select-field";
import { SelectEntry } from "../../formulaire/elements/select-entry";
import { I18nService } from "../../services/internationalisation.service";
import { SelectFieldReference } from "../../formulaire/select-field-reference";
import { SelectFieldReference } from "../../formulaire/elements/select-field-reference";
import { ApplicationSetupService } from "../../services/app-setup.service";
@Component({
......
import { Component, Input, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { SelectEntry } from "../../formulaire/select-entry";
import { SelectEntry } from "../../formulaire/elements/select-entry";
import { FormulaireService } from "../../services/formulaire.service";
import { FieldsetContainer } from "../../formulaire/fieldset-container";
import { SelectFieldModel } from "../../formulaire/select-field-model";
import { FieldsetContainer } from "../../formulaire/elements/fieldset-container";
import { SelectFieldModel } from "../../formulaire/elements/select-field-model";
@Component({
selector: "select-model-field-line",
......
import { NG_VALIDATORS, Validator, AbstractControl, ValidatorFn } from "@angular/forms";
import { Directive, Input } from "@angular/core";
import { NgBaseParam } from "../components/base-param-input/base-param-input.component";
import { NgParameter } from "../formulaire/ngparam";
import { NgParameter } from "../formulaire/elements/ngparam";
import { sprintf } from "sprintf-js";
import { ServiceFactory } from "../services/service-factory";
......
import { FormulaireDefinition } from "../form-definition";
import { CalculatorResults } from "../../../results/calculator-results";
import { FormResult } from "../form-result";
import { FormCompute } from "../form-compute";
import { FormResultFixedVar } from "../form-result-fixedvar";
import { FormComputeFixedVar } from "../form-compute-fixedvar";
import { ServiceFactory } from "../../../services/service-factory";
export class FormulaireBase extends FormulaireDefinition {
protected _formCompute: FormCompute;
protected _formResult: FormResult;
constructor() {
super();
this._formResult = new FormResultFixedVar(this);
this._formCompute = new FormComputeFixedVar(this, (this._formResult as FormResultFixedVar));
}
protected completeParse(json: {}) {
super.completeParse(json);
this._formResult.helpLinks = this._resultsHelpLinks;
}
/**
* Resets the form results, the results panel on screen, the model
* results, and does the same for all depending modules
* @param symbol symbol of the parameter whose value change triggered this method
* @param forceResetAllDependencies if true, even non-calculated non-modified parameters
* links will be considered as dependencies @see jalhyd#98
*/
public resetResults(visited: string[] = [], symbol?: string, forceResetAllDependencies: boolean = false) {
visited.push(this.currentNub.uid);
// reset GUI results
this._formResult.resetResults();
// reset model results
this.currentNub.resetResult();
// reset the result panels of all forms depending on this one
ServiceFactory.instance.formulaireService.resetAllDependingFormsResults(this, visited, symbol, forceResetAllDependencies);
}
public doCompute() {
this._formCompute.doCompute();
}
public get hasResults(): boolean {
return this._formResult.hasResults;
}
public get results(): CalculatorResults[] {
return this._formResult.results;
}
}
import { Pab } from "jalhyd";
import { FormulaireBase } from "./form-base";
import { FormComputePab } from "../form-compute-pab";
import { FormResultPab } from "../form-result-pab";
/**
* Formulaire pour les passes à bassins, inspiré du formulaire
* pour les structures en parallèle
*/
export class FormulairePab extends FormulaireBase {
constructor() {
super();
this._formResult = new FormResultPab(this);
// remove obsolete observer set by super()
this.removeObserver(this._formCompute);
this._formCompute = new FormComputePab(this, (this._formResult as FormResultPab));
}
public get pabNub(): Pab {
return this.currentNub as Pab;
}
}
import { IObservable, Nub, Session, SectionNub } from "jalhyd";
import { FormResultSection } from "../form-result-section";
import { FormDefSection } from "../form-def-section";
import { FormComputeSectionParametree } from "../form-compute-section-parametree";
import { FieldSet } from "../../fieldset";
import { FormulaireBase } from "./form-base";
export class FormulaireSectionParametree extends FormulaireBase {
private _formSection: FormDefSection;
constructor() {
super();
this._formSection = new FormDefSection(this);
this._formResult = new FormResultSection(this);
// remove obsolete observer set by super()
this.removeObserver(this._formCompute);
this._formCompute = new FormComputeSectionParametree(
this, this._formSection, (this._formResult as FormResultSection)
);
}
protected parseOptions(json: {}) {
super.parseOptions(json);
this._formSection.parseOptions(json);
}
public afterParseFieldset(fs: FieldSet) {
this._formSection.afterParseFieldset(fs);
}
// interface Observer
update(sender: IObservable, data: any) {
// super.update(sender, data);
if (sender instanceof Nub) {
switch (data.action) {
case "resultUpdated":
// forward Nub results update notification to FormCompute objects
this.notifyNubResultUpdated(sender);
break;
}
}
// changement de propriété du FieldSet contenant le select de choix du type de section
if (sender instanceof FieldSet && data.action === "propertyChange") {
switch (sender.id) {
case "fs_section":
// replace underlying section without replacing whole Nub
const newSect = Session.getInstance().createSection(data.value);
(this._currentNub as SectionNub).setSection(newSect);
// reflect changes in GUI
for (const fs of this.allFieldsets) {
// show / hide dependent fields
fs.updateFields();
}
this.reset();
break;
case "fs_computed_var":
this.reset();
break;
}
}
}
}
import { IObservable, SectionNub, Session, BiefRegime } from "jalhyd";
import { FormDefSection } from "../form-def-section";
import { FieldSet } from "../../fieldset";
import { FormulaireBase } from "./form-base";
import { FieldSet } from "../elements/fieldset";
import { FormulaireSection } from "./form-section";
export class FormulaireBief extends FormulaireBase {
private _formSection: FormDefSection;
export class FormulaireBief extends FormulaireSection {
/** id du select configurant le régime */
private _regimeSelectId: string;
constructor() {
super();
this._formSection = new FormDefSection(this);
// default properties
this._props["regime"] = BiefRegime.Fluvial;
}
protected parseOptions(json: {}) {
super.parseOptions(json);
this._formSection.parseOptions(json);
// id du select configurant la méthode de résolution
this._regimeSelectId = this.getOption(json, "regimeSelectId");
}
public afterParseFieldset(fs: FieldSet) {
this._formSection.afterParseFieldset(fs);
// si le FieldSet contient le select de méthode de résolution
if (this._regimeSelectId) {
const sel = fs.getFormulaireNodeById(this._regimeSelectId);
......
import { acSection, Result, CourbeRemousParams, CourbeRemous } from "jalhyd";
import { RemousResults } from "../../results/remous-results";
import { FormulaireDefinition } from "./form-definition";
import { FormCompute } from "./form-compute";
import { FormResultRemous } from "./form-result-remous";
export class FormComputeCourbeRemous extends FormCompute {
private resultYn: Result;
private resultYc: Result;
constructor(formBase: FormulaireDefinition, formResult: FormResultRemous) {
super(formBase, formResult);
}
private get remousResults(): RemousResults {
const f = this._formResult as FormResultRemous;
return f.remousResults;
}
protected compute() {
this.reaffectResultComponents();
}
protected reaffectResultComponents() {
const cr: CourbeRemous = this._formBase.currentNub as CourbeRemous;
const prmCR: CourbeRemousParams = cr.prms as CourbeRemousParams;
this.remousResults.parameters = prmCR;
// variable supplémentaire à calculer
this.remousResults.extraParamSymbol = this._formBase.currentNub.properties.getPropValue("varCalc");
// calcul
this.remousResults.result = cr.CalcSerie();
const sect: acSection = cr.Sn;
this.resultYn = sect.CalcSection("Yn"); // hauteur normale
this.resultYc = sect.CalcSection("Yc"); // hauteur critique
// données du graphe
this.remousResults.hauteurNormale = this.resultYn.resultElement;
this.remousResults.hauteurCritique = this.resultYc.resultElement;
if (this.remousResults.extraParamSymbol) {
this.remousResults.extraChart = ! ["Hs", "Hsc", "Ycor", "Ycon"].includes(this.remousResults.extraParamSymbol);
} else {
this.remousResults.extraChart = false;
}
}
}
import { Nub } from "jalhyd";
import { FormCompute } from "./form-compute";
import { NgParameter } from "../ngparam";
import { FormResultFixedVar } from "./form-result-fixedvar";
import { FormulaireDefinition } from "./form-definition";
export class FormComputeFixedVar extends FormCompute {
constructor(formBase: FormulaireDefinition, formResult: FormResultFixedVar) {
super(formBase, formResult);
}
protected get formResult(): FormResultFixedVar {
return this._formResult as FormResultFixedVar;
}
protected compute() {
this.runNubCalc(this._formBase.currentNub);
this.reaffectResultComponents();
}
protected reaffectResultComponents() {
const nub: Nub = this._formBase.currentNub;
const computedParam: NgParameter = this.getComputedParameter();
this.formResult.resetResults(); // to avoid adding fixed parameters more than once (see below)
this.formResult.addFixedParameters();
const varParams: NgParameter[] = this.getVariatedParameters();
if (varParams.length === 0) {
// pas de paramètre à varier
this.formResult.fixedResults.result = nub.result;
if (computedParam !== undefined) {
this.formResult.fixedResults.calculatedParameter = computedParam;
}
} else {
// il y a un paramètre à varier
this.formResult.varResults.variatedParameters = varParams;
if (computedParam !== undefined) {
this.formResult.varResults.calculatedParameter = computedParam;
}
this.formResult.varResults.result = nub.result;
this.formResult.varResults.update();
}
}
}
import { Result, MacrorugoCompound } from "jalhyd";
import { FormulaireDefinition } from "./form-definition";
import { FormCompute } from "./form-compute";
import { FormResultMacrorugoCompound } from "./form-result-macrorugo-compound";
import { NgParameter } from "../ngparam";
export class FormComputeMacrorugoCompound extends FormCompute {
constructor(formBase: FormulaireDefinition, formResult: FormResultMacrorugoCompound) {
super(formBase, formResult);
}
protected get formResult(): FormResultMacrorugoCompound {
return this._formResult as FormResultMacrorugoCompound;
}
protected compute() {
this.runNubCalc(this._formBase.currentNub);
// reset variable index to avoid trying to access an index > 0 when nothing varies
const mrcr = this.formResult.mrcResults;
mrcr.variableIndex = 0;
this.reaffectResultComponents();
}
protected reaffectResultComponents() {
const mrc: MacrorugoCompound = (this._formBase.currentNub as MacrorugoCompound);
const computedParam: NgParameter = this.getComputedParameter();
const varParams: NgParameter[] = this.getVariatedParameters();
// résultat de calcul de la passe à macrorugo complexe
const mrcr = this.formResult.mrcResults;
mrcr.calculatedParameter = computedParam;
mrcr.result = mrc.result;
if (varParams) {
mrcr.variatedParameters = varParams;
}
// résultat de chaque enfant
const cr: Result[] = [];
for (const c of mrc.children) {
cr.push(c.result);
}
mrcr.childrenResults = cr;
}
}
import { Structure, ParamDefinition } from "jalhyd";
import { FormComputeFixedVar } from "./form-compute-fixedvar";
export class FormComputeParallelStructures extends FormComputeFixedVar {
/**
* construit un identifiant de type { uid: "abcdef", symbol: "X" }
* avec "abcdef" l'index de l'ouvrage et "X" son paramètre
*/
protected getParameterRefid(p: ParamDefinition): any {
const nub = p.parentComputeNode;
if (nub instanceof Structure) {
return {
uid: nub.uid,
symbol: p.symbol
};
} else {
return super.getParameterRefid(p);
}
}
}
import { SectionParametree, acSection, Result, ParamDefinition, Nub } from "jalhyd";
import { FormCompute } from "./form-compute";
import { FormDefSection } from "./form-def-section";
import { FormResultSection } from "./form-result-section";
import { VarResults } from "../../results/var-results";
import { SectionResults } from "../../results/section-results";
import { FormulaireDefinition } from "./form-definition";
export class FormComputeSectionParametree extends FormCompute {
constructor(formBase: FormulaireDefinition, private _formSection: FormDefSection, formResult: FormResultSection) {
super(formBase, formResult);
}
private get _formSectionResult(): FormResultSection {
return this._formResult as FormResultSection;
}
private get _varResults(): VarResults {
return this._formSectionResult.varResults;
}
private get _sectionResults(): SectionResults {
return this._formSectionResult.sectionResults;
}
protected compute() {
this.runNubCalc(this._formBase.currentNub);
this.reaffectResultComponents();
}
protected runNubCalc(nub: Nub, computedParam?: ParamDefinition): Result {
return nub.CalcSerie();
}
protected reaffectResultComponents() {
const sectNub: SectionParametree = this._formBase.currentNub as SectionParametree;
const sect: acSection = sectNub.section;
this._sectionResults.section = sect;
const varParams = this._formSection.getSectionVariatedParameters();
if (varParams.length > 0) {
// résultats variés avec tous les résultats complémentaires
this._varResults.variatedParameters = varParams;
this._varResults.result = sectNub.result;
this._varResults.update();
} else {
// résultats de section (avec le graphique de section)
this._sectionResults.result = sectNub.result;
// résultats complémentaires des paramètres fixés
this._formSectionResult.addSectionFixedParameters();
this._formSectionResult.fixedResults.result = sectNub.result;
}
}
}
import { Nub, Result, ParamDomainValue, Observer, ParamDefinition } from "jalhyd";
import { FormResult } from "./form-result";
import { FormulaireDefinition } from "./form-definition";
import { NgParameter, ParamRadioConfig } from "../ngparam";
export abstract class FormCompute implements Observer {
constructor(protected _formBase: FormulaireDefinition, protected _formResult: FormResult) {
// indirectly subscribe to Nub result updates
this._formBase.addObserver(this);
}
protected abstract compute();
protected get formResult(): FormResult {
return this._formResult;
}
/**
* retourne un identifiant du paramètre dans le formulaire
* surchargé dans le cas des ouvrages //
*/
protected getParameterRefid(p: ParamDefinition) {
return p.symbol;
}
/**
* Copies current Nub result into result components for display on page.
* Should be called every time the Nub result changes.
* Must be idempotent.
*/
protected abstract reaffectResultComponents();
/**
* Lance le calcul d'un paramètre en déterminant une valeur initiale.
* Si nécessaire déclenche un calcul en chaîne des modules en amont.
*/
protected runNubCalc(nub: Nub): Result {
return nub.CalcSerie();
}
protected getComputedParameter(): NgParameter {
const cpd = this._formBase.currentNub.calculatedParam;
let ngparam: NgParameter;
if (cpd !== undefined) {
ngparam = this._formBase.getParamFromSymbol(cpd.symbol);
if (ngparam === undefined) { // calculated parameter is not displayed on screen
ngparam = new NgParameter(cpd, this._formBase);
}
}
return ngparam;
}
protected getVariatedParameters(): NgParameter[] {
let res: NgParameter[] = [];
// find variated local parameters
res = this._formBase.getDisplayedParamListFromState(ParamRadioConfig.VAR);
// add variated linked parameters
const pms = this._formBase.getDisplayedParamListFromState(ParamRadioConfig.LINK);
for (const p of pms) {
if (p.paramDefinition.hasMultipleValues) {
res.push(p);
}
}
return res;
}
/**
* Triggers computation of the Nub, updates form results
*/
public doCompute() {
// calculate module
this.compute();
// refresh results
this._formBase.notifyObservers({
"action": "resultsUpdated",
}, this._formBase);
}
// interface Observer
public update(sender: any, data: any): void {
if (sender instanceof Nub) {
switch (data.action) {
case "nubResultUpdated":
// forward Nub results update notification to FormCompute objects
this.reaffectResultComponents();
break;
}
}
}
}
import { IObservable, MethodeResolution, SectionNub, Session } from "jalhyd";
import { IObservable, MethodeResolution, SectionNub, Session, Result, CourbeRemous, CourbeRemousParams, acSection } from "jalhyd";
import { FormResultRemous } from "../form-result-remous";
import { FormDefSection } from "../form-def-section";
import { FormComputeCourbeRemous } from "../form-compute-courbe-remous";