diff --git a/src/index.ts b/src/index.ts index 92585173f8371312e54518a1e6fe139b48a8ac2e..cf56f425510c0ddd8984ad984715844b48d6712b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ export * from "./param/param-values"; export * from "./compute-node"; export * from "./nub"; export * from "./nub_factory"; +export * from "./session_nub"; export * from "./cond_distri"; export * from "./dichotomie"; export * from "./lechaptcalmon"; diff --git a/src/nub_factory.ts b/src/nub_factory.ts index 14ad9c6a0d0b8cd4f54922635b70aae700256ece..7a8409d8015bdd5ff4d07a62b1983d3892725e9a 100644 --- a/src/nub_factory.ts +++ b/src/nub_factory.ts @@ -1,5 +1,6 @@ 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"; @@ -24,7 +25,11 @@ export class NubFactory { private static _instance: NubFactory; // instance pour le pattern singleton - private constructor() { } + private _session: SessionNub[]; + + private constructor() { + this._session = []; + } public static getInstance() { if (NubFactory._instance == undefined) @@ -36,13 +41,34 @@ export class NubFactory { this._defaultPrecision = p; } + /** + * créé un Nub et l'ajoute à la session + */ + public createSessionNub(p: Props | {}): SessionNub { + const params = p instanceof Props ? p : new Props(p); + const nub = this.createNub(params); + const res = new SessionNub(nub, params); + this._session.push(res); + return res; + } + + public findSessionNub(params: Props | {}): SessionNub { + for (const n of this._session) + if (n.hasProperties(params)) + return n; + return undefined; + } + /** * créé un Nub * @param calcType type de Nub * @param nodeType sous type de Nub * @param params paramètres supplémentaires spécifiques */ - public createNub(calcType: CalculatorType, nodeType: ComputeNodeType, params?: any): Nub { + private createNub(params: Props): Nub { + const calcType: CalculatorType = params.getPropValue("calcType"); + const nodeType: ComputeNodeType = params.getPropValue("nodeType"); + switch (calcType) { case CalculatorType.ConduiteDistributrice: { @@ -113,8 +139,8 @@ export class NubFactory { } case CalculatorType.Structure: - const structType: StructureType = params.structureType; - const loiDebit: LoiDebit = params.loiDebit; + const structType: StructureType = params.getPropValue("structureType"); + const loiDebit: LoiDebit = params.getPropValue("loiDebit"); return CreateStructure(structType, loiDebit); case CalculatorType.ParallelStructure: diff --git a/src/section/section_nub.ts b/src/section/section_nub.ts index a9c0938906fa7ce363b739d44e219a2abc9d5abd..476a83bfef117789cc957f4627e5b440568d157a 100644 --- a/src/section/section_nub.ts +++ b/src/section/section_nub.ts @@ -144,8 +144,7 @@ export class SectionParametree extends Nub { } private hasVariatedParameter(): boolean { - for (const k in this._prms.map) { - const p: ParamDefinition = this._prms.map[k]; + for (const p of this.parameterIterator) { switch (p.valueMode) { case ParamValueMode.LISTE: case ParamValueMode.MINMAX: diff --git a/src/session_nub.ts b/src/session_nub.ts new file mode 100644 index 0000000000000000000000000000000000000000..55dd6d18bc38c27adc4a496186694fcca3eda9a9 --- /dev/null +++ b/src/session_nub.ts @@ -0,0 +1,66 @@ +import { Nub } from "./nub"; + +/** + * gestion d'un ensemble de propriétés (clé/valeur) + */ +export class Props { + constructor(private _props: any = {}) { } + + public hasProperties(props: Props | {}): boolean { + const keys = Object.keys(this._props); + const p = props instanceof Props ? props.props : props; + + // if (keys.length != Object.keys(p).length) + // return false; + + for (const k of keys) + if (this._props[k] !== p[k]) + return false; + + return true; + } + + public getPropValue(key: string): any { + return this._props[key]; + } + + public setPropValue(key: string, val: any): any { + this._props[key] = val; + } + + public get props() { + return this._props; + } + + public clone(): Props { + const res = new Props(); + for (const k in this._props) + res._props[k] = this._props[k]; + return res; + } +} + +/** + * Nub utilisé dans une session + */ +export class SessionNub { + private _props: Props; + + constructor(private _nub: Nub, props: Props | {}) { + if (this._nub == undefined) + throw new Error(`NgNub.constructor() : argument invalide`); + + if (props instanceof Props) + this._props = props.clone(); + else + this._props = new Props(props); + } + + public get nub() { + return this._nub; + } + + public hasProperties(p: Props | {}): boolean { + return this._props.hasProperties(p); + } +}