diff --git a/src/nub_factory.ts b/src/nub_factory.ts index 483d250d838092bd4ed4783095ecc40b78a00ed4..2f4e19b6117d813b1f4ee77feb31f9298c8c66c9 100644 --- a/src/nub_factory.ts +++ b/src/nub_factory.ts @@ -1,53 +1,53 @@ -import { ComputeNodeType, CalculatorType } from "./compute-node" -import { Nub } from "./nub" -import { SessionNub, Props } from "./session_nub" -import { ConduiteDistribParams, ConduiteDistrib } from "./cond_distri"; -import { LechaptCalmonParams, LechaptCalmon } from "./lechaptcalmon"; - -import { acSection } from "./section/section_type"; -import { ParamsSectionTrapez, cSnTrapez } from "./section/section_trapez"; -import { ParamsSectionRectang, cSnRectang } from "./section/section_rectang"; -import { ParamsSectionCirc, cSnCirc } from "./section/section_circulaire"; -import { ParamsSectionPuiss, cSnPuiss } from "./section/section_puissance"; -import { SectionParametree } from "./section/section_nub"; -import { RegimeUniforme } from "./regime_uniforme"; -import { CourbeRemousParams, MethodeResolution, CourbeRemous } from "./remous"; -import { PabDimensionParams, PabDimension } from "./pab/pab_dimension"; +import { CalculatorType, ComputeNodeType } from "./compute-node"; +import { Nub } from "./nub"; +import { Props, SessionNub } from "./session_nub"; + +// Calculettes +import { ConduiteDistrib, ConduiteDistribParams } from "./cond_distri"; +import { LechaptCalmon, LechaptCalmonParams } from "./lechaptcalmon"; +import { PabDimension, PabDimensionParams } from "./pab/pab_dimension"; import { PabPuissance, PabPuissanceParams } from "./pab/pab_puissance"; +import { RegimeUniforme } from "./regime_uniforme"; +import { CourbeRemous, CourbeRemousParams, MethodeResolution } from "./remous"; +import { SectionParametree } from "./section/section_nub"; +import { Dever, DeverParams } from "./structure/dever"; +import { ParallelStructure, ParallelStructureParams } from "./structure/parallel_structure"; + +// Classes relatives aux sections +import { cSnCirc, ParamsSectionCirc } from "./section/section_circulaire"; +import { cSnPuiss, ParamsSectionPuiss } from "./section/section_puissance"; +import { cSnRectang, ParamsSectionRectang } from "./section/section_rectang"; +import { cSnTrapez, ParamsSectionTrapez } from "./section/section_trapez"; +import { acSection } from "./section/section_type"; + +// Classes relatives aux structures import { CreateStructure } from "./structure/factory_structure"; -import { StructureType, LoiDebit } from "./structure/structure_props"; import { Structure } from "./structure/structure"; -import { ParallelStructure } from "./structure/parallel_structure"; -import { ParallelStructureParams } from "./structure/parallel_structure_params"; -import { DeverParams, Dever } from "./structure/dever"; +import { LoiDebit, StructureType } from "./structure/structure_props"; export class NubFactory { - private _defaultPrecision: number = 0.001; + + public static getInstance() { + if (NubFactory._instance === undefined) { + NubFactory._instance = new NubFactory(); + } + return NubFactory._instance; + } private static _instance: NubFactory; // instance pour le pattern singleton + private _defaultPrecision: number = 0.001; + private _session: SessionNub[]; - private constructor() { + constructor() { this._session = []; } - public static getInstance() { - if (NubFactory._instance == undefined) - NubFactory._instance = new NubFactory(); - return NubFactory._instance; - } - public setDefaultPrecision(p: number) { this._defaultPrecision = p; } - private newSessionNub(p: Props | {}): SessionNub { - const params = p instanceof Props ? p : new Props(p); - const nub = this.createNub(params); - return new SessionNub(nub, params); - } - /** * créé un Nub et l'ajoute à la session */ @@ -58,60 +58,12 @@ export class NubFactory { } public findSessionNub(params: Props | {}): SessionNub { - for (const n of this._session) - if (n.hasProperties(params)) + for (const n of this._session) { + if (n.hasProperties(params)) { return n; - return undefined; - } - - private replaceStructureNub(oldNub: Nub, newNub: Nub) { - const b1 = oldNub instanceof Structure; - const b2 = newNub instanceof Structure; - if ((b1 && !b2) || (!b1 && b2)) - throw new Error(`NubFactory.replaceStructureNub() : arguments incorrects (${typeof (oldNub)}/${typeof (newNub)}`); - if (b1 && b2) { - for (const sn of this._session) - if (sn.nub instanceof ParallelStructure) { - const psn = sn.nub as ParallelStructure; - let i = 0; - for (const st of psn.structures) { - if (st.uid == oldNub.uid) { - psn.replaceStructure(i, newNub as Structure); - return; - } - i++; - } - } - throw new Error(`NubFactory.replaceStructureNub() : la structure (uid ${oldNub.uid}) à remplacer n'a pas été trouvée`); - } - - // copie (dans la mesure du possible) des modes de valeur des paramètres - - for (const p of newNub.parameters) - try { - const p2 = oldNub.getParameter(p.symbol); - p.valueMode = p2.valueMode; } - catch (e) { - } - } - - private deleteStructureNub(n: Nub) { - if (n instanceof Structure) { - for (const sn of this._session) - if (sn.nub instanceof ParallelStructure) { - const psn = sn.nub as ParallelStructure; - let i = 0; - for (const st of psn.structures) { - if (st.uid == n.uid) { - psn.deleteStructure(i); - return; - } - i++; - } - } - throw new Error(`NubFactory.deleteStructureNub() : la structure (uid ${n.uid}) à supprimer n'a pas été trouvée`); } + return undefined; } /** @@ -122,7 +74,7 @@ export class NubFactory { public replaceSessionNub(sn: SessionNub, params: Props): SessionNub { let i = 0; for (const n of this._session) { - if (n.uid == sn.uid) { + if (n.uid === sn.uid) { const newNub = this.newSessionNub(params); this._session[i] = newNub; this.replaceStructureNub(sn.nub, newNub.nub); @@ -135,20 +87,6 @@ export class NubFactory { return undefined; } - /** - * recherche du nub ouvrages parallèles possédant l'ouvrage donné - */ - private findParallelStructureWithNub(n: Nub) { - for (const s of this._session) - if (s.nub instanceof ParallelStructure) { - const res = s.nub as ParallelStructure; - if (res.hasStructure(n)) - return res; - } - - return undefined; - } - /** * déplace un SessionNub associé à un nub Structure d'une position vers le début de la liste de structures * @param sn SessionNub à remplacer @@ -161,10 +99,10 @@ export class NubFactory { if (psn) { let i = 0; for (const n of this._session) { - if (n.uid == sn.uid && i > 0) { - const n = this._session[i - 1]; + if (n.uid === sn.uid && i > 0) { + const nS: SessionNub = this._session[i - 1]; this._session[i - 1] = this._session[i]; - this._session[i] = n; + this._session[i] = nS; psn.moveStructureUp(sn.nub as Structure); return; } @@ -172,7 +110,9 @@ export class NubFactory { } } - throw new Error(`NubFactory.moveStructureNubUp() : la structure (uid ${sn.uid}) à déplacer n'a pas été trouvée`); + throw new Error( + `NubFactory.moveStructureNubUp() : la structure (uid ${sn.uid}) à déplacer n'a pas été trouvée` + ); } /** @@ -187,10 +127,10 @@ export class NubFactory { if (psn) { let i = 0; for (const n of this._session) { - if (n.uid == sn.uid && i < this._session.length - 1) { - const n = this._session[i]; + if (n.uid === sn.uid && i < this._session.length - 1) { + const nS: SessionNub = this._session[i]; this._session[i] = this._session[i + 1]; - this._session[i + 1] = n; + this._session[i + 1] = nS; psn.moveStructureDown(sn.nub as Structure); return; } @@ -198,7 +138,102 @@ export class NubFactory { } } - throw new Error(`NubFactory.moveStructureNubDown() : la structure (uid ${sn.uid}) à déplacer n'a pas été trouvée`); + throw new Error( + `NubFactory.moveStructureNubDown() : la structure (uid ${sn.uid}) à déplacer n'a pas été trouvée` + ); + } + + public deleteSessionNub(sn: SessionNub) { + let i = 0; + for (const n of this._session) { + if (n.uid === sn.uid) { + this._session.splice(i, 1); + this.deleteStructureNub(sn.nub); + return; + } + i++; + } + throw new Error(`NubFactory.deleteSessionNub() : le SessionNub (uid ${sn.uid}) à supprimer n'a pas été trouvé`); + } + + private newSessionNub(p: Props | {}): SessionNub { + const params = p instanceof Props ? p : new Props(p); + const nub = this.createNub(params); + return new SessionNub(nub, params); + } + + private replaceStructureNub(oldNub: Nub, newNub: Nub) { + const b1 = oldNub instanceof Structure; + const b2 = newNub instanceof Structure; + if ((b1 && !b2) || (!b1 && b2)) { + throw new Error( + `NubFactory.replaceStructureNub() : arguments incorrects (${typeof (oldNub)}/${typeof (newNub)}` + ); + } + if (b1 && b2) { + for (const sn of this._session) { + if (sn.nub instanceof ParallelStructure) { + const psn = sn.nub as ParallelStructure; + let i = 0; + for (const st of psn.structures) { + if (st.uid === oldNub.uid) { + psn.replaceStructure(i, newNub as Structure); + return; + } + i++; + } + } + } + throw new Error( + `NubFactory.replaceStructureNub() : la structure (uid ${oldNub.uid}) à remplacer n'a pas été trouvée` + ); + } + + // copie (dans la mesure du possible) des modes de valeur des paramètres + for (const p of newNub.parameters) { + try { + const p2 = oldNub.getParameter(p.symbol); + p.valueMode = p2.valueMode; + } catch (e) { + // ??? + } + } + } + + private deleteStructureNub(n: Nub) { + if (n instanceof Structure) { + for (const sn of this._session) { + if (sn.nub instanceof ParallelStructure) { + const psn = sn.nub as ParallelStructure; + let i = 0; + for (const st of psn.structures) { + if (st.uid === n.uid) { + psn.deleteStructure(i); + return; + } + i++; + } + } + } + throw new Error( + `NubFactory.deleteStructureNub() : la structure (uid ${n.uid}) à supprimer n'a pas été trouvée` + ); + } + } + + /** + * recherche du nub ouvrages parallèles possédant l'ouvrage donné + */ + private findParallelStructureWithNub(n: Nub) { + for (const s of this._session) { + if (s.nub instanceof ParallelStructure) { + const res = s.nub as ParallelStructure; + if (res.hasStructure(n)) { + return res; + } + } + } + return undefined; } /** @@ -245,11 +280,10 @@ export class NubFactory { const ru = new RegimeUniforme(sect); return ru; - case CalculatorType.CourbeRemous: { - const sect: acSection = this.createSection(nodeType); - const prms = new CourbeRemousParams(sect, 0.15, // Yamont = tirant amont + const sectCR: acSection = this.createSection(nodeType); + const prms = new CourbeRemousParams(sectCR, 0.15, // Yamont = tirant amont 0.4, // Yaval = tirant aval 100, // Long= Longueur du bief 5, // Dx=Pas d'espace @@ -305,23 +339,13 @@ export class NubFactory { } default: - throw new Error(`NubFactory.createNub() : calculatrice '${CalculatorType[calcType]}' / noeud de calcul '${ComputeNodeType[nodeType]}' non pris en charge`); + throw new Error( + // tslint:disable-next-line:max-line-length + `NubFactory.createNub() : calculatrice '${CalculatorType[calcType]}' / noeud de calcul '${ComputeNodeType[nodeType]}' non pris en charge` + ); } } - public deleteSessionNub(sn: SessionNub) { - let i = 0; - for (const n of this._session) { - if (n.uid == sn.uid) { - this._session.splice(i, 1); - this.deleteStructureNub(sn.nub); - return; - } - i++; - } - throw new Error(`NubFactory.deleteSessionNub() : le SessionNub (uid ${sn.uid}) à supprimer n'a pas été trouvé`); - } - private createSection(nt: ComputeNodeType): acSection { switch (nt) { case ComputeNodeType.None: // pour les paramètres communs, n'importe quelle section convient @@ -340,7 +364,6 @@ export class NubFactory { return new cSnTrapez(prms); } - case ComputeNodeType.SectionRectangle: { const prms = new ParamsSectionRectang(0.8, // tirant d'eau @@ -389,4 +412,4 @@ export class NubFactory { // public get sessionNubIterator(): IterableIterator<SessionNub> { // return this._session[Symbol.iterator](); // crée un itérateur à partir d'un tableau // } -} \ No newline at end of file +} diff --git a/src/structure/parallel_structure.ts b/src/structure/parallel_structure.ts index 5c2e115f731f7ffa81ebee42a9e2e35179f456ea..60299bc80d0f0b9872c038f3185b0d8a52820dfd 100644 --- a/src/structure/parallel_structure.ts +++ b/src/structure/parallel_structure.ts @@ -3,10 +3,13 @@ import { ParamCalculability } from "../param/param-definition"; import { Result } from "../util/result"; import { ParallelStructureParams } from "./parallel_structure_params"; import { Structure } from "./structure"; -import { IParamDefinitionIterator, ParamsEquation, ParamsEquationArrayIterator } from "../param/params-equation"; -import { ParamValues } from "../param/param-values"; -import { NamedIterableValues } from "../param/param-value-iterator"; + import { BaseParam } from "../param/param-base"; +import { NamedIterableValues } from "../param/param-value-iterator"; +import { ParamValues } from "../param/param-values"; +import { IParamDefinitionIterator, ParamsEquation, ParamsEquationArrayIterator } from "../param/params-equation"; + +export { ParallelStructureParams }; /** * Interface pour mémoriser le n° d'ouvrage et le paramètre à calculer @@ -215,6 +218,71 @@ export class ParallelStructure extends Nub { return res; } + // interface IReferencedNub + public getReferencedObject(desc: string): NamedIterableValues { + try { + // analyse n.X + const i: IStructureVarCalc = this.getStructureVarCalc(desc); + return this.structures[i.index].getParameter(i.prm); + } catch (e) { + try { + // analyse ouvrage[n].X + const i: IStructureVarCalc = this.getStructureVarCalc2(desc); + return this.structures[i.index].result.getExtraResult(i.prm); + } catch (e) { + // ??? + } + } + // pas de la forme n.X ou ouvrage[n].X ou erreur sur n ou X + return super.getReferencedObject(desc); + } + + public getReferencedParamValues(desc: string): ParamValues { + try { + const ro = this.getReferencedObject(desc); + if (ro instanceof BaseParam) { + return ro.paramValues; + } + return undefined; + } catch (e) { + // pas de la forme n.X ou ouvrage[n].X ou erreur sur n ou X + const param = this.getParameter(desc); + if (param === undefined) { + return undefined; + } + return param.paramValues; + } + } + + public getReferencedExtraResult(desc: string): any { + return this._result.getExtraResult(desc); + } + + /** + * liste des valeurs (paramètre, résultat, résultat complémentaire) liables à un paramètre + * @param src objet qui sert de clé de recherche des paramètres liables, de type INamedObject | string + * @returns tableau d'objets de la forme : + * { "name":string, "value":NamedIterableValues, "nub":Nub}, nub=Nub d'origine de la "value" + */ + public getLinkableValues(src: any): any[] { + // paramètres liables de ce Nub + let res = super.getLinkableValues(src); + + let i = 0; + for (const s of this.structures) { + // paramètres liables des Nub structures enfants + const l = s.getLinkableValues(src, `${i}.`, true); + + // on remplace les nubs retournés par this (à cause du préfixe) + for (const lv of l) { + lv.nub = this; + } + res = res.concat(l); + i++; + } + return res; + } + /** * paramétrage de la calculabilité des paramètres */ @@ -260,9 +328,11 @@ export class ParallelStructure extends Nub { private getStructureVarCalc2(sVarCalc: string): IStructureVarCalc { const re = /([A-Z,a-z]+)\[(\d+)\]\.(.+)/; const match = re.exec(sVarCalc); - if (match === null || match[1] != "ouvrage") - throw new Error(`getStructureVarCalc2() : erreur d'analyse de ${sVarCalc}, (pas de la forme ouvrage[n].X)`); - + if (match === null || match[1] !== "ouvrage") { + throw new Error( + `getStructureVarCalc2() : erreur d'analyse de ${sVarCalc}, (pas de la forme ouvrage[n].X)` + ); + } return { index: +match[2], prm: match[3] }; } @@ -280,68 +350,4 @@ export class ParallelStructure extends Nub { return this.structures[sVC.index].Calc(sVC.prm, rInit, rPrec); } - // interface IReferencedNub - - public getReferencedObject(desc: string): NamedIterableValues { - try { - // analyse n.X - const i: IStructureVarCalc = this.getStructureVarCalc(desc); - return this.structures[i.index].getParameter(i.prm); - } - catch (e) { - try { - // analyse ouvrage[n].X - const i: IStructureVarCalc = this.getStructureVarCalc2(desc); - return this.structures[i.index].result.getExtraResult(i.prm); - } - catch (e) { - } - } - // pas de la forme n.X ou ouvrage[n].X ou erreur sur n ou X - return super.getReferencedObject(desc); - } - - public getReferencedParamValues(desc: string): ParamValues { - try { - const ro = this.getReferencedObject(desc); - if (ro instanceof BaseParam) - return ro.paramValues; - return undefined; - } - catch (e) { - // pas de la forme n.X ou ouvrage[n].X ou erreur sur n ou X - const param = this.getParameter(desc); - if (param === undefined) - return undefined; - return param.paramValues; - } - } - - public getReferencedExtraResult(desc: string): any { - return this._result.getExtraResult(desc); - } - - /** - * liste des valeurs (paramètre, résultat, résultat complémentaire) liables à un paramètre - * @param src objet qui sert de clé de recherche des paramètres liables, de type INamedObject | string - * @returns tableau d'objets de la forme { "name":string, "value":NamedIterableValues, "nub":Nub}, nub=Nub d'origine de la "value" - */ - public getLinkableValues(src: any): any[] { - // paramètres liables de ce Nub - let res = super.getLinkableValues(src); - - let i = 0; - for (const s of this.structures) { - // paramètres liables des Nub structures enfants - const l = s.getLinkableValues(src, `${i}.`, true); - - // on remplace les nubs retournés par this (à cause du préfixe) - for (const lv of l) - lv.nub = this; - - res = res.concat(l); - i++; - } - return res; - } }