Skip to content
Snippets Groups Projects
Commit 2820a58b authored by mathias.chouet's avatar mathias.chouet
Browse files

Update developers doc

parent 1f25dee8
No related branches found
No related tags found
No related merge requests found
......@@ -356,6 +356,77 @@ export * from "./addition";
export * from "./addition_params";
```
## Further considerations for adding more complex modules
### properties
If the module uses **properties**, one should add a default value in the Nub's constructor for each property (see "Properties" above). The Nub should then register itself as **observer** of properties values changes. Example from `Trigo`:
```TypeScript
constructor(prms: TrigoParams, dbg: boolean = false) {
this._props.addObserver(this);
this.properties.setPropValue("trigoOperation", TrigoOperation.COS);
}
```
Note that value should be set after registering the observer, so that the changes observation mechanism is properly triggered.
The changes observation mechanism should be added by implementing `Observer` interface, and creating an `update()` method as in the following example:
```TypeScript
public update(sender: any, data: any) {
if (data.action === "propertyChange" && data.name === "trigoOperation") {
// do something
}
}
```
If the acceptable values for a property are picked from an **enum**, then to properly serialize it one has to add a `case` in `invertEnumKeysAndValuesInProperties()` method of `session.ts`:
```TypeScript
case "trigoOperation":
res[k] = TrigoOperation[res[k]];
break;
```
Finally, for all the property values to be properly tested by fuzzy unit tests, one has to add a `case` in `CreateTestNub()` method, as well as a new method, in `spec/fuzzing.spec.ts`:
```TypeScript
function CreateTestNub(iCalType: number): Nub {
if (iCalType === CalculatorType.Trigo) {
setRandomTrigoOperation(n as Trigo);
}
}
function setRandomTrigoOperation(sn: Trigo) {
const op = Math.floor(Math.random() * 6); // enum has 6 values
sn.properties.setPropValue("trigoOperation", op);
}
```
### Nubs with children
If a module has children, the `childrenType` attribute should be set in the Nub's constructor. This attribute is used for translation in GUIs, notably ngHyd. Example from `MacroRugoCompound`:
```TypeScript
constructor(prms: MacrorugoCompoundParams, dbg: boolean = false) {
this._childrenType = "MacroRugo";
```
When implementing parent's `Equation()` method, children should be calculated using `Calc()` and not `Equation()` or `Solve()`, so that their logs and results are properly attached to them.
```TypeScript
public Equation(sVarCalc: string): Result {
for (const child of this.children) {
child.Calc(sVarCalc);
}
```
## How to set up a new hydraulic structure equation
@TODO
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment