jalhyd
Version:
JaLHyd, a Javascript Library for Hydraulics
103 lines • 3.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SectionNub = void 0;
const internal_modules_1 = require("../../internal_modules");
const internal_modules_2 = require("../../internal_modules");
/**
* A Nub that contains an acSection (ex: RegimeUniforme, SectionParametree, Remous)
*/
class SectionNub extends internal_modules_2.Nub {
constructor(prms, dbg = false) {
super(prms, dbg);
this._sectionVars = {};
}
/** Section is always the first child */
get section() {
if (this._children && this._children.length > 0) {
return this._children[0];
}
else {
return undefined;
}
}
getParameter(name) {
if (typeof name !== "string") {
// dirty hack because calculated param descriptor for section params is an object { uid: , symbol: }
name = name.symbol;
}
let res = super.getParameter(name);
if (res === undefined) {
// not found - maybe a section var ?
res = this._sectionVars[name];
if (!res) {
throw new Error(`in ${this.constructor.name}, SectionNub.getParameter() : nom de paramètre ${name} incorrect`);
}
}
return res;
}
/**
* Once session is loaded, run a second pass on all linked parameters to
* reset their target if needed
*/
fixLinks(obj) {
// return value
const ret = {
hasErrors: false
};
// iterate over parameters
super.fixLinks(obj);
// iterate over children if any
if (obj.children && Array.isArray(obj.children)) {
for (const s of obj.children) {
// get the Nub
const subNub = internal_modules_1.Session.getInstance().findNubByUid(s.uid);
const res = subNub.fixLinks(s);
// forward errors
if (res.hasErrors) {
ret.hasErrors = true;
}
}
}
return ret;
}
/**
* Proxy to setSection() to ensure extra code is executed when
* unserialising session (a SectionNub child can only be the
* one and only Section)
*/
addChild(child, after) {
this.setSection(child);
}
/**
* Sets / replaces the current section
*/
setSection(s) {
if (s) {
// prevent index out of bounds at first time
if (this._children.length === 0) {
this._children[0] = undefined;
}
this.replaceChild(0, s);
this._props.removeProp("nodeType"); // because this property belongs to child section and is set as long as section is not defined
/**
* Y linkability managed in child classes through 'visible' flag
* @see Bief,CourbeRemous
*/
}
}
// interface IProperties
getPropValue(key) {
if (this.childHasProperty(key)) {
return this.section.getPropValue(key);
}
return this._props.getPropValue(key);
}
setPropValue(key, val, sender) {
if (this.childHasProperty(key)) {
return this.section.setPropValue(key, val, sender);
}
return this._props.setPropValue(key, val, sender);
}
}
exports.SectionNub = SectionNub;
//# sourceMappingURL=section_nub.js.map