implemented disabling of blocks and routes

This commit is contained in:
Stephan Richter
2020-11-02 10:41:34 +01:00
parent 416a9cd2df
commit 817c8fb60d
6 changed files with 31 additions and 5 deletions

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId> <groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId> <artifactId>web4rail</artifactId>
<version>0.9.15</version> <version>0.9.16</version>
<name>Web4Rail</name> <name>Web4Rail</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<description>Java Model Railway Control</description> <description>Java Model Railway Control</description>

View File

@@ -22,6 +22,7 @@ DelayedAction : verzögerte Aktion
delete : entfernen delete : entfernen
delete route : Route löschen delete route : Route löschen
Destination\: {} from {} : Ziel: {} von {} Destination\: {} from {} : Ziel: {} von {}
disabled : deaktiviert
editable train properties : veränderliche Zug-Eigenschaften editable train properties : veränderliche Zug-Eigenschaften
Emergency : Notfall Emergency : Notfall
FinishRoute : Route abschließen FinishRoute : Route abschließen
@@ -38,6 +39,7 @@ Manage trains : Züge verwalten
Maximum train length\: : maximale Zug-Länge Maximum train length\: : maximale Zug-Länge
Move tiles : Kacheln verschieben Move tiles : Kacheln verschieben
name\: : Name: name\: : Name:
No free routes from {} : keine Route von {} frei
Online Documentation : Online-Dokumentation Online Documentation : Online-Dokumentation
other train properties : andere Zug-Eigenschaften other train properties : andere Zug-Eigenschaften
Origin and destination : Start und Ziel Origin and destination : Start und Ziel
@@ -61,6 +63,7 @@ SetSignalsToStop : Signale auf Halt stellen
SetSpeed : Geschwindigkeit ändern SetSpeed : Geschwindigkeit ändern
Setup actions : Aktivierungs-Aktionen Setup actions : Aktivierungs-Aktionen
Signals : Signale Signals : Signale
Started {} : {} gestartet
StopAuto : Automatikmodus abschalten StopAuto : Automatikmodus abschalten
STRAIGHT : gerade STRAIGHT : gerade
Tags : Markierungen Tags : Markierungen
@@ -81,4 +84,8 @@ Turn allowed : Wenden erlaubt
Turnouts : Weichen Turnouts : Weichen
TurnTrain : Fahrtrichtung umkehren TurnTrain : Fahrtrichtung umkehren
Unknown action\: {} : Unbekannte Aktion: {} Unknown action\: {} : Unbekannte Aktion: {}
unset : ungesetzt unset : ungesetzt
Was not able to assign {} to {}! : Konnte {} nicht an {} zuweisen!
Was not able to lock {} : Konnte {} nicht reservieren
Was not able to set all signals! : Konnte nicht alle Signale stellen!
Was not able to set all turnouts! : Konnte nicht alle Weichen stellen!

View File

@@ -54,4 +54,5 @@ public interface Constants {
public static final String NBSP = "&nbsp;"; public static final String NBSP = "&nbsp;";
public static final String CONTEXT = "context"; public static final String CONTEXT = "context";
public static final String GITHUB_URL = "https://github.com/srsoftware-de/Web4Rail"; public static final String GITHUB_URL = "https://github.com/srsoftware-de/Web4Rail";
public static final String DISABLED = "disabled";
} }

View File

@@ -32,6 +32,7 @@ import de.srsoftware.web4rail.actions.SetSpeed;
import de.srsoftware.web4rail.conditions.Condition; import de.srsoftware.web4rail.conditions.Condition;
import de.srsoftware.web4rail.moving.Train; import de.srsoftware.web4rail.moving.Train;
import de.srsoftware.web4rail.tags.Button; import de.srsoftware.web4rail.tags.Button;
import de.srsoftware.web4rail.tags.Checkbox;
import de.srsoftware.web4rail.tags.Fieldset; import de.srsoftware.web4rail.tags.Fieldset;
import de.srsoftware.web4rail.tags.Form; import de.srsoftware.web4rail.tags.Form;
import de.srsoftware.web4rail.tags.Input; import de.srsoftware.web4rail.tags.Input;
@@ -71,6 +72,7 @@ public class Route implements Constants{
public Direction startDirection; public Direction startDirection;
private Direction endDirection; private Direction endDirection;
private boolean disabled = false;
private static final String TRIGGER = "trigger"; private static final String TRIGGER = "trigger";
private static final String ACTIONS = "actions"; private static final String ACTIONS = "actions";
@@ -236,8 +238,9 @@ public class Route implements Constants{
new Input(ID,id()).hideIn(form); new Input(ID,id()).hideIn(form);
if (params.containsKey(CONTEXT)) new Input(CONTEXT,params.get(CONTEXT)).hideIn(form); if (params.containsKey(CONTEXT)) new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
Tag label = new Tag("label").content(t("name:")+NBSP); Tag label = new Tag("label").content(t("name:")+NBSP);
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name()).style("width: 80%").addTo(label); new Input(NAME, name()).style("width: 80%").addTo(label);
label.addTo(form); label.addTo(form);
new Checkbox(DISABLED, t("disabled"), disabled).addTo(form);
new Button(t("Apply"),form).addTo(form).addTo(win); new Button(t("Apply"),form).addTo(form).addTo(win);
} }
@@ -268,6 +271,7 @@ public class Route implements Constants{
* @return false, if any of the associated conditions is not fulfilled * @return false, if any of the associated conditions is not fulfilled
*/ */
public boolean allowed(Context context) { public boolean allowed(Context context) {
if (disabled) return false;
for (Condition condition : conditions) { for (Condition condition : conditions) {
if (!condition.fulfilledBy(context)) return false; if (!condition.fulfilledBy(context)) return false;
} }
@@ -415,6 +419,8 @@ public class Route implements Constants{
String name = name(); String name = name();
if (name != null) json.put(NAME, name); if (name != null) json.put(NAME, name);
if (disabled) json.put(DISABLED, true);
return json.toString(); return json.toString();
} }
@@ -451,6 +457,7 @@ public class Route implements Constants{
if (json.has(ACTIONS)) { if (json.has(ACTIONS)) {
setupActions = ActionList.load(json.getJSONArray(ACTIONS)); setupActions = ActionList.load(json.getJSONArray(ACTIONS));
} }
if (json.has(DISABLED)) disabled = json.getBoolean(DISABLED);
return plan.registerRoute(this); return plan.registerRoute(this);
} }
@@ -618,6 +625,8 @@ public class Route implements Constants{
String name = params.get(NAME); String name = params.get(NAME);
if (name != null) name(name); if (name != null) name(name);
disabled = "on".equals(params.get(DISABLED));
Condition condition = Condition.create(params.get(REALM_CONDITION)); Condition condition = Condition.create(params.get(REALM_CONDITION));
if (condition != null) { if (condition != null) {
conditions.add(condition); conditions.add(condition);

View File

@@ -61,6 +61,7 @@ public abstract class Condition implements Constants {
} }
public static Condition create(String type) { public static Condition create(String type) {
if (type == null) return null;
try { try {
return (Condition) Class.forName(PREFIX+"."+type).getDeclaredConstructor().newInstance(); return (Condition) Class.forName(PREFIX+"."+type).getDeclaredConstructor().newInstance();
} catch (Exception e) { } catch (Exception e) {

View File

@@ -31,6 +31,7 @@ import de.srsoftware.web4rail.Route;
import de.srsoftware.web4rail.Window; import de.srsoftware.web4rail.Window;
import de.srsoftware.web4rail.moving.Train; import de.srsoftware.web4rail.moving.Train;
import de.srsoftware.web4rail.tags.Button; import de.srsoftware.web4rail.tags.Button;
import de.srsoftware.web4rail.tags.Checkbox;
import de.srsoftware.web4rail.tags.Form; import de.srsoftware.web4rail.tags.Form;
import de.srsoftware.web4rail.tags.Input; import de.srsoftware.web4rail.tags.Input;
import de.srsoftware.web4rail.tags.Radio; import de.srsoftware.web4rail.tags.Radio;
@@ -58,6 +59,7 @@ public abstract class Tile implements Constants{
protected HashSet<Shadow> shadows = new HashSet<>(); protected HashSet<Shadow> shadows = new HashSet<>();
private HashSet<Route> routes = new HashSet<>(); private HashSet<Route> routes = new HashSet<>();
protected Plan plan; protected Plan plan;
private boolean disabled = false;
protected static Logger LOG = LoggerFactory.getLogger(Tile.class); protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
@@ -92,7 +94,7 @@ public abstract class Tile implements Constants{
} }
public boolean free() { public boolean free() {
return route == null; return (!disabled) && route == null;
} }
public int height() { public int height() {
@@ -122,6 +124,7 @@ public abstract class Tile implements Constants{
json.put(POS, pos); json.put(POS, pos);
if (route != null) json.put(ROUTE, route.id()); if (route != null) json.put(ROUTE, route.id());
if (oneWay != null) json.put(ONEW_WAY, oneWay); if (oneWay != null) json.put(ONEW_WAY, oneWay);
if (disabled) json.put(DISABLED, true);
return json; return json;
} }
@@ -152,6 +155,7 @@ public abstract class Tile implements Constants{
x = pos.getInt(X); x = pos.getInt(X);
y = pos.getInt(Y); y = pos.getInt(Y);
if (json.has(ONEW_WAY)) oneWay = Direction.valueOf(json.getString(ONEW_WAY)); if (json.has(ONEW_WAY)) oneWay = Direction.valueOf(json.getString(ONEW_WAY));
if (json.has(DISABLED)) disabled = json.getBoolean(DISABLED);
return this; return this;
} }
@@ -185,7 +189,8 @@ public abstract class Tile implements Constants{
new Input(ACTION, ACTION_UPDATE).hideIn(form); new Input(ACTION, ACTION_UPDATE).hideIn(form);
new Input(REALM, REALM_PLAN).hideIn(form); new Input(REALM, REALM_PLAN).hideIn(form);
new Input(ID,id()).hideIn(form); new Input(ID,id()).hideIn(form);
List<Direction> pd = possibleDirections(); List<Direction> pd = possibleDirections();
if (!pd.isEmpty()) { if (!pd.isEmpty()) {
new Tag("h4").content(t("One way:")).addTo(form); new Tag("h4").content(t("One way:")).addTo(form);
@@ -202,6 +207,8 @@ public abstract class Tile implements Constants{
String formId = "tile-properties-"+id(); String formId = "tile-properties-"+id();
Tag form = propForm(formId); Tag form = propForm(formId);
if (form!=null && form.children().size()>3) { if (form!=null && form.children().size()>3) {
new Checkbox(DISABLED, t("disabled"), disabled).addTo(form);
new Button(t("Apply"),"submitForm('"+formId+"')").addTo(form); new Button(t("Apply"),"submitForm('"+formId+"')").addTo(form);
form.addTo(window); form.addTo(window);
} else { } else {
@@ -370,6 +377,7 @@ public abstract class Tile implements Constants{
oneWay = null; oneWay = null;
} }
} }
disabled = "on".equals(params.get(DISABLED));
return this; return this;
} }
} }