jalhyd
Version:
JaLHyd, a Javascript Library for Hydraulics
383 lines • 14.4 kB
TypeScript
import { CalculatorType, ComputeNode } from "../internal_modules";
import { LinkedValue } from "../internal_modules";
import { Nub } from "../internal_modules";
import { Interval } from "../internal_modules";
import { IObservable, Observer } from "../internal_modules";
import { ParamDomain, ParamDomainValue } from "../internal_modules";
import { INamedIterableValues, INumberIterator } from "../internal_modules";
import { ParamValueMode } from "../internal_modules";
import { ParamValues } from "../internal_modules";
import { ParamsEquation } from "../internal_modules";
/**
* Calculabilité du paramètre
*/
export declare enum ParamCalculability {
/** parameter may have any value, may not vary, may not be calculated */
FIXED = 0,
/** parameter may have any value, may vary, may not be calculated */
FREE = 1,
/** parameter may have any value, may vary, may be calculated analytically */
EQUATION = 2,
/** parameter may have any value, may vary, may be calculated using numerical method */
DICHO = 3
}
/**
* Parameter family: defines linkability with other parameters/results
*/
export declare enum ParamFamily {
ANY = 0,
LENGTHS = 1,
WIDTHS = 2,
SLOPES = 3,
HEIGHTS = 4,
BASINFALLS = 5,
TOTALFALLS = 6,
ELEVATIONS = 7,
VOLUMES = 8,
FLOWS = 9,
DIAMETERS = 10,
SPEEDS = 11,
STRICKLERS = 12,
BLOCKCONCENTRATION = 13
}
/**
* Strategy to apply when multiple parameters are variating, and
* values series have to be extended for sizes to match
*/
export declare enum ExtensionStrategy {
REPEAT_LAST = 0,
RECYCLE = 1
}
/**
* Paramètre avec symbole, famille, domaine de définition, calculabilité,
* pointant éventuellement vers un autre paramètre / résultat
*/
export declare class ParamDefinition implements INamedIterableValues, IObservable {
/** le paramètre doit-il être exposé (par ex: affiché par l'interface graphique) ? */
visible: boolean;
/** sandbox value used during calculation */
v: number;
/** value used to initialize "DICHO" calculation, never supposed to be undefined */
private _initValue;
/** extension strategy, when multiple parameters vary */
private _extensionStrategy;
/** symbole */
private _symbol;
/** unité */
private _unit;
/** related parameters groups; indirectly gives access to the Nub using this parameter */
private _parent;
/** domaine de définition */
private _domain;
/** calculabilité */
private _calc;
/** valeur(s) prise(s) */
private _paramValues;
/** parameters family, for linking */
private _family;
/** pointer to another Parameter / Result, in case of LINK mode */
private _referencedValue;
/** implémentation par délégation de IObservable */
private _observable;
/**
* @param nullParams true if provided value must be ignored (@see nghyd/enableEmptyFieldsOnFormInit)
*/
constructor(parent: ParamsEquation, symb: string, d: ParamDomain | ParamDomainValue, unit?: string, val?: number, family?: ParamFamily, visible?: boolean, nullParams?: boolean);
/**
* set parent a-posteriori; used by nghyd when populating forms
*/
/**
* identifiant unique de la forme
* (uid du JalhydObject (en général un Nub) + "_" + symbole du paramètre)
* ex: 123_Q
*/
get uid(): string;
get unit(): string;
setUnit(u: string): void;
get initValue(): number;
/**
* Make sure that this value is never undefined, null or NaN, so that
* there is always an initial value for "DICHO" calculations, even
* when param value was set to undefined before
*/
set initValue(v: number);
/**
* @see getParentComputeNode()
*/
get parentComputeNode(): ComputeNode;
/**
* pointer to the ComputeNode (usually Nub) that uses the ParamsEquation that
* uses this ParamDefinition; for Section params, if returnEnclosingNubForSections
* is true, this will return the Nub enclosing the Section, otherwise the section itself
*/
getParentComputeNode(returnEnclosingNubForSections?: boolean): ComputeNode;
/**
* Returns the parent compute node as Nub if it is a Nub; returns
* undefined otherwise
*/
get parentNub(): Nub;
/**
* Identifiant unique du Nub parent
*/
get nubUid(): string;
/**
* Type de module du Nub parent
*/
get nubCalcType(): CalculatorType;
get symbol(): string;
setDomain(d: any): void;
get domain(): ParamDomain;
get interval(): Interval;
get extensionStrategy(): ExtensionStrategy;
set extensionStrategy(strategy: ExtensionStrategy);
get valueMode(): ParamValueMode;
/**
* Easy setter that propagates the change to other parameters
* (default behaviour); use setValueMode(..., false) to prevent
* possible infinite loops
*/
set valueMode(newMode: ParamValueMode);
/**
* Sets the value mode and asks the Nub to ensure there is only one parameter
* in CALC mode
*
* If propagateToCalculatedParam is true, any param that goes from CALC mode
* to any other mode will trigger a reset of the default calculated param at
* Nub level
*
* Propagates modes other than CALC and LINK to the underlying
* ParamValues (local instance)
*/
setValueMode(newMode: ParamValueMode, propagateToCalculatedParam?: boolean): void;
private propagateValueMode;
/**
* Returns true if this parameter is the calculatedParam of
* its parent Nub
*/
get isCalculated(): boolean;
/**
* Sets this parameter as the one to be calculated
*/
setCalculated(): void;
/**
* Current values set associated to this parameter; in LINK mode, points
* to a remote set of values.
*/
get paramValues(): ParamValues;
get referencedValue(): LinkedValue;
get family(): ParamFamily;
get calculability(): ParamCalculability;
set calculability(c: ParamCalculability);
/**
* Returns true if current value (not singleValue !) is defined
*/
get hasCurrentValue(): boolean;
/**
* Returns true if held value (not currentValue !) is defined,
* depending on the value mode
*/
get isDefined(): boolean;
get singleValue(): number;
set singleValue(v: number);
get min(): number;
set min(v: number);
get max(): number;
set max(v: number);
get step(): number;
set step(v: number);
/**
* Generates a reference step value, given the current (local) values for min / max
*/
get stepRefValue(): Interval;
get valueList(): number[];
set valueList(l: number[]);
count(): number;
/**
* Copies values of p into the current parameter, whatever the valueMode is; if
* p has linked values, the target values will be copied and the links won't be kept
* @param p a reference ParamDefinition or ParamValues to copy values from
*/
copyValuesFrom(p: ParamDefinition | ParamValues): void;
get currentValue(): number;
/**
* Get single value
*/
getValue(): number;
/**
* Returns values as a number list, for LISTE and MINMAX modes;
* in MINMAX mode, infers the list from min/max/step values
* @param extendTo if given, will extend the values list to this number of values
*/
getInferredValuesList(extendTo?: number): number[];
/**
* Magic method to define current values into Paramvalues set; defines the mode
* accordingly by detecting values nature
*/
setValues(o: number | any, max?: number, step?: number): void;
/**
* Sets the current value of the parameter's own values set, then
* notifies all observers
*/
setValue(val: number, sender?: any): void;
/**
* Same as setValue() but does not force SINGLE value mode; used for
* updating initial value of a DICHO calculated parameter
*/
setInitValue(val: number, sender?: any): void;
/**
* Validates the given numeric value against the definition domain; throws
* an error if value is outside the domain
*/
checkValueAgainstDomain(v: number): void;
checkMin(min: number): boolean;
checkMax(max: number): boolean;
checkMinMaxStep(step: number): boolean;
/**
* Return true if single value is valid regarding the domain constraints
*/
get isValueValid(): boolean;
get isMinMaxValid(): boolean;
/**
* Return true if current value is valid regarding the range constraints : min / max / step
*/
get isRangeValid(): boolean;
/**
* Root method to determine if a field value is valid, regarding the model constraints.
*
* Does not take care of input validation (ie: valid number, not empty...) because an
* invalid input should never be set as a value; input validation is up to the GUI.
*
* In LINK mode :
* - if target is a parameter, checks validity of the target value against the local model constraints
* - if target is a result :
* - is result is already computed, checks validity of the target result against the local model constraints
* - if it is not, checks the "computability" of the target Nub (ie. validity of the Nub) to allow
* triggering chain computation
*/
get isValid(): boolean;
/**
* Sets the current parameter to LINK mode, pointing to the given
* symbol (might be a Parameter (computed or not) or an ExtraResult)
* of the given Nub
*
* Prefer @see defineReferenceFromLinkedValue() whenever possible
*
* @param nub
* @param symbol
*/
defineReference(nub: Nub, symbol: string): void;
/**
* Asks the Session for available linkabke values for the current parameter,
* and returns true if given { nub / symbol } pair is part of them
*/
isAcceptableReference(nub: Nub, symbol: string): boolean;
defineReferenceFromLinkedValue(target: LinkedValue): void;
undefineReference(): void;
isReferenceDefined(): boolean;
/**
* Returns an object representation of the Parameter's current state
* @param nubUidsInSession UIDs of Nubs that will be saved in session along with this one;
* useful to determine if linked parameters must be kept as links or have their value
* copied (if target is not in UIDs list); if undefined, wil consider all Nubs as
* available (ie. will not break links)
*/
objectRepresentation(nubUidsInSession?: string[]): {
symbol: string;
mode: string;
};
/**
* Fills the current Parameter, provided an object representation
* @param obj object representation of a Parameter state
* @returns object {
* calculated: boolean true if loaded parameter is in CALC mode
* hasErrors: boolean true if errors were encountered during loading
* }
*/
loadObjectRepresentation(obj: any, setCalcMode?: boolean): {
calculated: boolean;
hasErrors: boolean;
};
/**
* Returns true if both the Nub UID and the symbol are identical
*/
equals(p: ParamDefinition): boolean;
/**
* Returns true if this parameter's value can safely be linked to the
* given parameter "src" (ie. without leading to circular dependencies)
*/
isLinkableTo(src: ParamDefinition): boolean;
/**
* Returns true if this parameter is ultimately (after followink links chain) linked
* to a result or extra result of any of the given nubs.
* If followLinksChain is false, will limit theexploration to the first target level only
*/
isLinkedToResultOfNubs(nubs: Nub[], followLinksChain?: boolean): boolean;
/**
* Returns true if the current parameter is directly linked to the
* Nub having UID "uid", its parent or any of its children
* @param uid
* @param symbol symbol of the target parameter whose value change triggered this method;
* if current Parameter targets this symbol, Nub will be considered dependent
* @param includeValuesLinks if true, even if this Parameter targets a non-calculated non-modified
* parameter, Nub will be considered dependent @see jalhyd#98
*/
dependsOnNubFamily(uid: string, symbol?: string, includeValuesLinks?: boolean): boolean;
/**
* Transparent proxy to own values iterator or targetted values iterator (in LINK mode)
*/
get valuesIterator(): INumberIterator;
getExtendedValuesIterator(size: number): INumberIterator;
/**
* Returns true if there are more than 1 value associated to this parameter;
* might be its own values (MINMAX / LISTE mode), or targetted values (LINK mode)
*/
get hasMultipleValues(): boolean;
initValuesIterator(reverse?: boolean): INumberIterator;
get hasNext(): boolean;
next(): IteratorResult<number>;
/** trick method - use .next() instead, unless you are explicitely in jalhyd#222 case */
nextValue(): IteratorResult<number>;
[](): IterableIterator<number>;
/**
* ajoute un observateur à la liste
*/
addObserver(o: Observer): void;
/**
* supprime un observateur de la liste
*/
removeObserver(o: Observer): void;
/**
* notifie un événement aux observateurs
*/
notifyObservers(data: any, sender?: any): void;
/**
* variable calculable par l'équation ?
*/
isAnalytical(): boolean;
/**
* Get the highest nub in the child nub hierarchy
*/
get originNub(): Nub;
/**
* Renvoie la valeur actuelle du paramètre (valeur courante ou résultat si calculé)
*/
get V(): number;
clone(): ParamDefinition;
/**
* notification envoyée après la modification de la valeur du paramètre
*/
private notifyValueModified;
/**
* vérifie si un min/max est valide par rapport au domaine de définition
*/
private isMinMaxDomainValid;
private checkMinMax;
private get isListValid();
/**
* Throws an error if this.paramValues._valueMode is not the expected value mode.
* In LINK mode, the tested valueMode is the mode of the ultimately targetted
* set of values (may never be LINK)
*/
private checkValueMode;
}
//# sourceMappingURL=param-definition.d.ts.map