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

Fix #353 - merge Formulaire classes

parent 8be6cb96
import { IObservable, Nub } from "jalhyd";
import { FieldSet } from "../../fieldset";
import { FieldsetContainer } from "../../fieldset-container";
import { FormulaireNode } from "../../formulaire-node";
import { NgParameter } from "../../ngparam";
import { FormResultMacrorugoCompound } from "../form-result-macrorugo-compound";
import { FormComputeMacrorugoCompound } from "../form-compute-macrorugo-compound";
import { IObservable, Nub, MacrorugoCompound, Result } from "jalhyd";
import { FieldSet } from "../elements/fieldset";
import { FieldsetContainer } from "../elements/fieldset-container";
import { FormulaireNode } from "../elements/formulaire-node";
import { NgParameter } from "../elements/ngparam";
import { FormulaireRepeatableFieldset } from "./form-repeatable-fieldset";
import { MacrorugoCompoundResults } from "../../results/macrorugo-compound-results";
import { CalculatorResults } from "../../results/calculator-results";
/**
* Formulaire pour les passes à macrorugosités complexes
......@@ -16,16 +16,13 @@ export class FormulaireMacrorugoCompound extends FormulaireRepeatableFieldset {
/** id of select configuring apron type */
private _apronTypeSelectId: string;
protected _mrcResults: MacrorugoCompoundResults;
constructor() {
super();
this._formResult = new FormResultMacrorugoCompound(this);
this._mrcResults = new MacrorugoCompoundResults();
// default properties
this._props["inclinedApron"] = false;
// remove obsolete observer set by super()
this.removeObserver(this._formCompute);
this._formCompute = new FormComputeMacrorugoCompound(this, (this._formResult as FormResultMacrorugoCompound));
}
protected parseOptions(json: {}) {
......@@ -76,7 +73,7 @@ export class FormulaireMacrorugoCompound extends FormulaireRepeatableFieldset {
protected completeParse(json: {}) {
this.subscribeFieldsetContainer();
this.updateApronState(this.currentNub.properties.getPropValue("inclinedApron"));
this._formResult.helpLinks = this._resultsHelpLinks;
this.helpLinks = this._resultsHelpLinks;
}
protected get fieldsetContainer(): FieldsetContainer {
......@@ -133,6 +130,53 @@ export class FormulaireMacrorugoCompound extends FormulaireRepeatableFieldset {
}
}
protected compute() {
this.runNubCalc(this.currentNub);
// reset variable index to avoid trying to access an index > 0 when nothing varies
const mrcr = this.mrcResults;
mrcr.variableIndex = 0;
this.reaffectResultComponents();
}
protected reaffectResultComponents() {
const mrc: MacrorugoCompound = (this.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.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;
}
public get mrcResults() {
return this._mrcResults;
}
public resetFormResults() {
this._mrcResults.reset();
}
public get results(): CalculatorResults[] {
// ensure help links are propagated
this._mrcResults.helpLinks = this.helpLinks;
return [ this._mrcResults ];
}
public get hasResults(): boolean {
return this._mrcResults.hasResults;
}
// interface Observer
public update(sender: IObservable, data: any) {
......
import { Result, Pab } from "jalhyd";
import { Pab, Result } from "jalhyd";
import { FormulaireDefinition } from "./form-definition";
import { FormResultPab } from "./form-result-pab";
import { FormCompute } from "./form-compute";
import { NgParameter } from "../ngparam";
import { longestVarParam } from "../../../app/util";
import { PabResults } from "../../results/pab-results";
import { NgParameter } from "../elements/ngparam";
import { longestVarParam } from "../../util";
import { CalculatorResults } from "../../results/calculator-results";
export class FormComputePab extends FormCompute {
/**
* Formulaire pour les passes à bassins, inspiré du formulaire
* pour les structures en parallèle
*/
export class FormulairePab extends FormulaireDefinition {
constructor(formBase: FormulaireDefinition, formResult: FormResultPab) {
super(formBase, formResult);
protected _pabResults: PabResults;
constructor() {
super();
this._pabResults = new PabResults();
}
protected get formResult(): FormResultPab {
return this._formResult as FormResultPab;
public get pabNub(): Pab {
return this.currentNub as Pab;
}
protected compute() {
this.runNubCalc(this._formBase.currentNub);
this.runNubCalc(this.currentNub);
// reset variable index to avoid trying to access an index > 0 when nothing varies
const pabr = this.formResult.pabResults;
const pabr = this.pabResults;
pabr.variableIndex = 0;
this.reaffectResultComponents();
}
protected reaffectResultComponents() {
const pab: Pab = (this._formBase.currentNub as Pab);
const pab: Pab = (this.currentNub as Pab);
const computedParam: NgParameter = this.getComputedParameter();
const varParams: NgParameter[] = this.getVariatedParameters();
// résultat de calcul de la passe à bassins
const pabr = this.formResult.pabResults;
const pabr = this.pabResults;
pabr.calculatedParameter = computedParam;
pabr.result = pab.result;
......@@ -70,4 +77,22 @@ export class FormComputePab extends FormCompute {
pabr.variatedParameters = varParams;
}
}
public get pabResults() {
return this._pabResults;
}
public resetResults() {
this._pabResults.reset();
}
public get results(): CalculatorResults[] {
// ensure help links are propagated
this._pabResults.helpLinks = this.helpLinks;
return [ this._pabResults ];
}
public get hasResults(): boolean {
return this._pabResults.hasResults;
}
}
import { Structure, Nub, ParallelStructure, StructureProperties, Props, Session } from "jalhyd";
import { FormComputeParallelStructures } from "../form-compute-parallel-structures";
import { FormResultFixedVar } from "../form-result-fixedvar";
import { FieldsetContainer } from "../../fieldset-container";
import { FieldSet } from "../../fieldset";
import { SelectField } from "../../select-field";
import { NgParameter } from "../../ngparam";
import { FieldsetTemplate } from "../../fieldset-template";
import { FormulaireNode } from "../../formulaire-node";
import { Structure, Nub, ParallelStructure, StructureProperties, Props, Session, ParamDefinition } from "jalhyd";
import { FieldsetContainer } from "../elements/fieldset-container";
import { FieldSet } from "../elements/fieldset";
import { SelectField } from "../elements/select-field";
import { NgParameter } from "../elements/ngparam";
import { FieldsetTemplate } from "../elements/fieldset-template";
import { FormulaireNode } from "../elements/formulaire-node";
import { FormulaireRepeatableFieldset } from "./form-repeatable-fieldset";
export class FormulaireParallelStructure extends FormulaireRepeatableFieldset {
......@@ -17,15 +15,6 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset {
*/
private __ouvrageSelectId: string;
constructor() {
super();
this._formResult = new FormResultFixedVar(this);
// remove obsolete observer set by super()
this.removeObserver(this._formCompute);
this._formCompute = new FormComputeParallelStructures(this, (this._formResult as FormResultFixedVar));
}
protected parseOptions(json: {}) {
super.parseOptions(json);
......@@ -44,6 +33,22 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset {
}
}
/**
* 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);
}
}
public createFieldset(parent: FormulaireNode, json: {}, data?: {}, nub?: Nub): FieldSet {
if (json["calcType"] === "Structure") {
// indice après lequel insérer le nouveau FieldSet
......@@ -112,7 +117,7 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset {
protected completeParse(json: {}) {
this.subscribeFieldsetContainer();
this._formResult.helpLinks = this._resultsHelpLinks;
this.helpLinks = this._resultsHelpLinks;
}
protected get fieldsetContainer(): FieldsetContainer {
......
import { IObservable, Observer, Session, SectionNub } from "jalhyd";
import { FormDefSection } from "../form-def-section";
import { FieldSet } from "../../fieldset";
import { FormulaireBase } from "./form-base";
export class FormulaireRegimeUniforme extends FormulaireBase implements Observer {
import { FieldSet } from "../elements/fieldset";
import { FormulaireSection } from "./form-section";
private _formSection: FormDefSection;
constructor() {
super();
this._formSection = new FormDefSection(this);
}
protected parseOptions(json: {}) {
super.parseOptions(json);
this._formSection.parseOptions(json);
}
public afterParseFieldset(fs: FieldSet) {
this._formSection.afterParseFieldset(fs);
}
protected completeParse(json: {}) {
super.completeParse(json);
this._formResult.helpLinks = this._resultsHelpLinks;
}
// interface Observer
export class FormulaireRegimeUniforme extends FormulaireSection implements Observer {
update(sender: IObservable, data: any) {
super.update(sender, data);
......
import { FieldSet } from "../../fieldset";
import { FieldsetContainer } from "../../fieldset-container";
import { FormulaireBase } from "./form-base";
import { FieldsetTemplate } from "../../fieldset-template";
import { FieldSet } from "../elements/fieldset";
import { FieldsetContainer } from "../elements/fieldset-container";
import { FormulaireFixedVar } from "./form-fixedvar";
import { FieldsetTemplate } from "../elements/fieldset-template";
import { Props, Session, Nub } from "jalhyd";
export abstract class FormulaireRepeatableFieldset extends FormulaireBase {
export abstract class FormulaireRepeatableFieldset extends FormulaireFixedVar {
protected abstract get fieldsetContainer(): FieldsetContainer;
......
import { FormulaireDefinition } from "./form-definition";
import { FormResult } from "./form-result";
import { CalculatorResults } from "../../results/calculator-results";
import { MacrorugoCompoundResults } from "../../results/macrorugo-compound-results";
export class FormResultMacrorugoCompound extends FormResult {
protected _formBase: FormulaireDefinition;
protected _mrcResults: MacrorugoCompoundResults;
constructor(base: FormulaireDefinition) {
super();
this._formBase = base;
this._mrcResults = new MacrorugoCompoundResults();
}
public get mrcResults() {
return this._mrcResults;
}
public resetResults() {
this._mrcResults.reset();
}
public get results(): CalculatorResults[] {
// ensure help links are propagated
this._mrcResults.helpLinks = this.helpLinks;
return [ this._mrcResults ];
}
public get hasResults(): boolean {
return this._mrcResults.hasResults;
}
}
import { FormulaireDefinition } from "./form-definition";
import { FormResult } from "./form-result";
import { CalculatorResults } from "../../results/calculator-results";
import { PabResults } from "../../results/pab-results";
export class FormResultPab extends FormResult {
protected _formBase: FormulaireDefinition;
protected _pabResults: PabResults;
constructor(base: FormulaireDefinition) {
super();
this._formBase = base;
this._pabResults = new PabResults();
}
public get pabResults() {
return this._pabResults;
}
public resetResults() {
this._pabResults.reset();
}
public get results(): CalculatorResults[] {
// ensure help links are propagated
this._pabResults.helpLinks = this.helpLinks;
return [ this._pabResults ];
}
public get hasResults(): boolean {
return this._pabResults.hasResults;
}
}
import { RemousResults } from "../../results/remous-results";
import { FormResult } from "./form-result";
import { FormulaireDefinition } from "./form-definition";
import { CalculatorResults } from "../../results/calculator-results";
export class FormResultRemous extends FormResult {
/**
* résultats de courbes de remous
*/
private _remousResults: RemousResults;
constructor(base: FormulaireDefinition) {
super();
this._remousResults = new RemousResults();
}
public get remousResults() {
return this._remousResults;
}
public resetResults() {
this._remousResults.reset();
}
public get hasResults(): boolean {
return this._remousResults.hasResults;
}
public get results(): CalculatorResults[] {
// ensure help links are propagated
this._remousResults.helpLinks = this.helpLinks;
return [ this._remousResults ];
}
}
import { CalculatorResults } from "../../results/calculator-results";
export abstract class FormResult {
/** copy of options.resultsHelp read by FormDefinition.parseOptions() */
public helpLinks: { [key: string]: string };
public abstract resetResults();
public abstract get hasResults(): boolean;
public abstract get results(): CalculatorResults[];
}
import { IObservable, Nub, Session, SectionNub, ParamDefinition, Result, SectionParametree, acSection } from "jalhyd";
import { FieldSet } from "../elements/fieldset";
import { FormulaireSection } from "./form-section";
import { SectionResults } from "../../results/section-results";
import { ParamRadioConfig } from "../ngparam";
import { FixedResults } from "../../results/fixed-results";
import { VarResults } from "../../results/var-results";
import { FormResult } from "./form-result";
import { FormulaireDefinition } from "./form-definition";
import { ParamRadioConfig } from "../elements/ngparam";
import { CalculatorResults } from "../../results/calculator-results";
export class FormResultSection extends FormResult {
private _formBase: FormulaireDefinition;
/**
* résultats fixes/variables
*/
private _fixedResults: FixedResults;
private _varResults: VarResults;
export class FormulaireSectionParametree extends FormulaireSection {
/**
* résultats de section paramétrée
*/
private _sectionResults: SectionResults;
constructor(base: FormulaireDefinition) {
public constructor() {
super();
this._formBase = base;
this._fixedResults = new FixedResults();
this._varResults = new VarResults();
this._sectionResults = new SectionResults();
}
public get fixedResults() {
return this._fixedResults;
protected compute() {
this.runNubCalc(this.currentNub);
this.reaffectResultComponents();
}
public get varResults() {
return this._varResults;
protected runNubCalc(nub: Nub, computedParam?: ParamDefinition): Result {
return nub.CalcSerie();
}
public get sectionResults() {
return this._sectionResults;
protected reaffectResultComponents() {
const sectNub: SectionParametree = this.currentNub as SectionParametree;
const sect: acSection = sectNub.section;
this._sectionResults.section = sect;
const varParams = this.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.addSectionFixedParameters();
this.fixedResults.result = sectNub.result;
}
}
public resetResults() {
public resetFormResults() {
this._fixedResults.reset();
this._varResults.reset();
this._sectionResults.reset();
}
public addSectionFixedParameters() {
for (const p of this._formBase.getDisplayedParamListFromState(ParamRadioConfig.FIX)) {
for (const p of this.getDisplayedParamListFromState(ParamRadioConfig.FIX)) {
this._fixedResults.addFixedParameter(p);
}
}
......@@ -69,4 +77,31 @@ export class FormResultSection extends FormResult {
res.push(this._sectionResults);
return res;
}
// interface Observer
update(sender: IObservable, data: any) {
super.update(sender, data);
// 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 { NgParameter, ParamRadioConfig } from "../ngparam";
import { FormulaireDefinition } from "./form-definition";
import { FieldSet } from "../fieldset";
import { NgParameter, ParamRadioConfig } from "../elements/ngparam";
import { FieldSet } from "../elements/fieldset";
import { FormulaireFixedVar } from "./form-fixedvar";
export class FormDefSection {
/**
* id de l'élément configurant le type de section
*/
private _sectionSourceId: string;
export abstract class FormulaireSection extends FormulaireFixedVar {
private _formBase: FormulaireDefinition;
constructor(base: FormulaireDefinition) {
this._formBase = base;
}
/** id de l'élément configurant le type de section */
private _sectionSourceId: string;
private get hasSectionNodeTypeSource(): boolean {
return this._sectionSourceId !== undefined;
}
public getSectionVariatedParameters(): NgParameter[] {
return this._formBase.getDisplayedParamListFromState(ParamRadioConfig.VAR);
return this.getDisplayedParamListFromState(ParamRadioConfig.VAR);
}