Commit 347ed123 authored by Grand Francois's avatar Grand Francois
Browse files

#46 : ajout de la classe SessionNub qui regroupe un nub et son contexte de...

 #46 : ajout de la classe SessionNub qui regroupe un nub et son contexte de création (type de calculette, de noeud, loi de débit...)
- NubFactory : gestion de la session avec une liste de SessionNub
Showing with 98 additions and 6 deletions
+98 -6
...@@ -7,6 +7,7 @@ export * from "./param/param-values"; ...@@ -7,6 +7,7 @@ export * from "./param/param-values";
export * from "./compute-node"; export * from "./compute-node";
export * from "./nub"; export * from "./nub";
export * from "./nub_factory"; export * from "./nub_factory";
export * from "./session_nub";
export * from "./cond_distri"; export * from "./cond_distri";
export * from "./dichotomie"; export * from "./dichotomie";
export * from "./lechaptcalmon"; export * from "./lechaptcalmon";
......
import { ComputeNodeType, CalculatorType } from "./compute-node" import { ComputeNodeType, CalculatorType } from "./compute-node"
import { Nub } from "./nub" import { Nub } from "./nub"
import { SessionNub, Props } from "./session_nub"
import { ConduiteDistribParams, ConduiteDistrib } from "./cond_distri"; import { ConduiteDistribParams, ConduiteDistrib } from "./cond_distri";
import { LechaptCalmonParams, LechaptCalmon } from "./lechaptcalmon"; import { LechaptCalmonParams, LechaptCalmon } from "./lechaptcalmon";
...@@ -24,7 +25,11 @@ export class NubFactory { ...@@ -24,7 +25,11 @@ export class NubFactory {
private static _instance: NubFactory; // instance pour le pattern singleton private static _instance: NubFactory; // instance pour le pattern singleton
private constructor() { } private _session: SessionNub[];
private constructor() {
this._session = [];
}
public static getInstance() { public static getInstance() {
if (NubFactory._instance == undefined) if (NubFactory._instance == undefined)
...@@ -36,13 +41,34 @@ export class NubFactory { ...@@ -36,13 +41,34 @@ export class NubFactory {
this._defaultPrecision = p; 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 * créé un Nub
* @param calcType type de Nub * @param calcType type de Nub
* @param nodeType sous type de Nub * @param nodeType sous type de Nub
* @param params paramètres supplémentaires spécifiques * @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) { switch (calcType) {
case CalculatorType.ConduiteDistributrice: case CalculatorType.ConduiteDistributrice:
{ {
...@@ -113,8 +139,8 @@ export class NubFactory { ...@@ -113,8 +139,8 @@ export class NubFactory {
} }
case CalculatorType.Structure: case CalculatorType.Structure:
const structType: StructureType = params.structureType; const structType: StructureType = params.getPropValue("structureType");
const loiDebit: LoiDebit = params.loiDebit; const loiDebit: LoiDebit = params.getPropValue("loiDebit");
return CreateStructure(structType, loiDebit); return CreateStructure(structType, loiDebit);
case CalculatorType.ParallelStructure: case CalculatorType.ParallelStructure:
......
...@@ -144,8 +144,7 @@ export class SectionParametree extends Nub { ...@@ -144,8 +144,7 @@ export class SectionParametree extends Nub {
} }
private hasVariatedParameter(): boolean { private hasVariatedParameter(): boolean {
for (const k in this._prms.map) { for (const p of this.parameterIterator) {
const p: ParamDefinition = this._prms.map[k];
switch (p.valueMode) { switch (p.valueMode) {
case ParamValueMode.LISTE: case ParamValueMode.LISTE:
case ParamValueMode.MINMAX: case ParamValueMode.MINMAX:
......
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);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment