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

PreBarrage

when deleting a wall, leave no basin without connection (connect to river upstream/downstream)
prevent deletion of walls that would be restored by the aforementioned mechanism
"del" hotkey to delete element on schema
parent a0dea38a
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,13 @@ import {
import * as mermaid from "mermaid";
import { HotkeysService, Hotkey } from 'angular2-hotkeys';
import { I18nService } from "../../services/internationalisation.service";
import { PbSchema } from "../../formulaire/elements/pb-schema";
import { DialogNewPbCloisonComponent } from "../dialog-new-pb-cloison/dialog-new-pb-cloison.component";
import { GenericCalculatorComponent } from "../generic-calculator/calculator.component";
import { AppComponent } from "../../app.component";
/**
* The interactive schema for calculator type "PreBarrage" (component)
......@@ -63,8 +66,11 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
public constructor(
@Inject(forwardRef(() => GenericCalculatorComponent)) private calculatorComponent: GenericCalculatorComponent,
private i18nService: I18nService,
private hotkeysService: HotkeysService,
private newPbCloisonDialog: MatDialog
) { }
) {
this.hotkeysService.add(new Hotkey("del", AppComponent.onHotkey(this.removeOnHotkey, this)));
}
public get selectedItem(): any {
return this._selectedItem;
......@@ -413,12 +419,42 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
}
public get enableRemoveButton() {
return (this._selectedItem !== undefined);
if (this._selectedItem === undefined) {
return false;
}
// if deleting a PbCloison would replace it by a new one at
// the same place (@see onRemoveClick), make it not deletable
if (this._selectedItem instanceof PbCloison) {
if ((
this._selectedItem.bassinAmont !== undefined
&& this._selectedItem.bassinAmont.cloisonsAval.length === 1
&& this._selectedItem.bassinAval === undefined
) || (
this._selectedItem.bassinAval !== undefined
&& this._selectedItem.bassinAval.cloisonsAmont.length === 1
&& this._selectedItem.bassinAmont === undefined
)) {
return false;
}
}
return true;
}
/** Removes a basin or wall, and all related items */
public onRemoveClick() {
this.model.deleteChild(this._selectedItem.findPositionInParent());
// never let an unconnected basin ! (not done in model to prevent unwanted
// automatic child addition when clearing children)
if (this._selectedItem instanceof PbCloison) {
// if no downstream connections remain, connect to river downstream
if (this._selectedItem.bassinAmont !== undefined && this._selectedItem.bassinAmont.cloisonsAval.length === 0) {
this.model.addChild(new PbCloison(this._selectedItem.bassinAmont, undefined));
}
// if no upstream connections remain, connect to river upstream
if (this._selectedItem.bassinAval !== undefined && this._selectedItem.bassinAval.cloisonsAmont.length === 0) {
this.model.addChild(new PbCloison(undefined, this._selectedItem.bassinAval));
}
}
this.unselect();
this.refresh();
}
......@@ -427,6 +463,13 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
return this.i18nService.localizeText("INFO_FIELDSET_REMOVE");
}
// listener for "del" hotkey
protected removeOnHotkey() {
if (this.enableRemoveButton) {
this.onRemoveClick();
}
}
public get enableCopyButton() {
return (this._selectedItem !== undefined && this._selectedItem instanceof PbCloison);
}
......@@ -559,7 +602,10 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
private updateValidity() {
// check that at least 1 basin is present and a route from river
// upstream to river downstream exists (2nd check includes 1st)
this._isValid = this.model.hasUpDownConnection();
this._isValid = (
this.model.hasUpDownConnection()
&& ! this.model.hasBasinNotConnected()
);
console.log("schéma valide", this._isValid);
this.validChange.emit();
}
......
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