Skip to content
Snippets Groups Projects
Commit 310ffa9f authored by Mathias Chouet's avatar Mathias Chouet Committed by mathias.chouet
Browse files

PreBarrage: enhance node selection on schema

parent 58660bd6
No related branches found
No related tags found
No related merge requests found
......@@ -391,6 +391,17 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
return desc;
}
/**
* Selects and highlights on the schema the given wall or basin
*/
private selectNodeOnSchema(element: PbBassin | PbCloison) {
this.nativeElement.querySelectorAll("g.node").forEach(item => {
if (item.id === element.uid) {
this.selectNode(item);
}
});
}
private findBasinPosition(basin: PbBassin): number {
let i = 0;
for (const b of this.model.bassins) {
......@@ -431,8 +442,9 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
const wall = this._selectedItem as PbCloison;
const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval);
this.model.addChild(wallCopy);
this.unselect(); // @TODO select new wall ?
this.unselect();
this.refresh();
this.selectNodeOnSchema(wallCopy);
}
public get uitextCopy() {
......@@ -441,9 +453,11 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
/** Adds a new lone basin */
public onAddBasinClick() {
this.model.addChild(new PbBassin(new PbBassinParams(20, 99)));
this.unselect(); // @TODO select new basin ?
const newBasin = new PbBassin(new PbBassinParams(20, 99));
this.model.addChild(newBasin);
this.unselect();
this.refresh();
this.selectNodeOnSchema(newBasin);
}
public get uitextAddBasin() {
......@@ -476,6 +490,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
this.model.addChild(wall);
this.unselect();
this.refresh();
this.selectNodeOnSchema(wall);
}
});
}
......@@ -496,7 +511,10 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
if (this._selectedItem instanceof PbBassin) {
this.model.moveBasin(this._selectedItem.uid, this.findBasinPosition(this._selectedItem) - 1);
}
const basin = this._selectedItem;
this.unselect();
this.refresh();
this.selectNodeOnSchema(basin);
}
public get uitextMoveBasinUp() {
......@@ -515,7 +533,10 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
if (this._selectedItem instanceof PbBassin) {
this.model.moveBasin(this._selectedItem.uid, this.findBasinPosition(this._selectedItem) + 1);
}
const basin = this._selectedItem;
this.unselect();
this.refresh();
this.selectNodeOnSchema(basin);
}
public get uitextMoveBasinDown() {
......@@ -568,6 +589,10 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
if (data.action === "refresh") {
this.unselect();
this.refresh();
// select a node on the schema ?
if (data.value !== undefined) {
this.selectNodeOnSchema(this.model.findChild(data.value));
}
}
}
}
......
......@@ -68,7 +68,10 @@ export class FormulairePbCloison extends FormulaireParallelStructure {
} else if (sender.id === this._downstreamBasinSelectId) {
nub.bassinAval = newBasin;
}
this.notifyObservers({ action: "updateBasin" }, this);
this.notifyObservers({
action: "updateBasin",
value: nub.uid // node to select on the schema
}, this);
}
}
}
......@@ -124,9 +124,9 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
}
}
private refreshSchema() {
private refreshSchema(nodeUidToSelect: string) {
const pbs = this.kids[0] as PbSchema;
pbs.refresh();
pbs.refresh(nodeUidToSelect);
}
// interface Observer
......@@ -136,7 +136,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
if (sender instanceof FormulairePbCloison) {
// console.log("HOH PUTAIN CE BIG QUATTRO HOYOYOYOYOY", this.kids[0].constructor.name);
if (data.action === "updateBasin") {
this.refreshSchema();
this.refreshSchema(data.value);
}
}
}
......
......@@ -24,7 +24,10 @@ export class PbSchema extends FormulaireElement {
}
/** Asks PbSchemaComponent to redraw the schema */
public refresh() {
this.notifyObservers({ action: "refresh" }, this);
public refresh(nodeUidToSelect: string) {
this.notifyObservers({
action: "refresh",
value: nodeUidToSelect
}, this);
}
}
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