improvement: manually-defined actions are now preserverd when plan is analyzed for new routes
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -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.10.7</version>
|
<version>0.10.8s</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>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ Control unit : Zentrale
|
|||||||
Current location\: : Aktueller Ort:
|
Current location\: : Aktueller Ort:
|
||||||
Actions and contacts : Aktionen und Kontakte
|
Actions and contacts : Aktionen und Kontakte
|
||||||
click here to setup contact : Hier klicken, um Kontakt auszuwählen
|
click here to setup contact : Hier klicken, um Kontakt auszuwählen
|
||||||
click here to setup relay : Hier klicken, um Relay einzurichten
|
click here to setup relay : Hier klicken, um Relais einzurichten
|
||||||
Create action : Aktion erzeugen
|
Create action : Aktion erzeugen
|
||||||
DelayedAction : verzögerte Aktion
|
DelayedAction : verzögerte Aktion
|
||||||
delete : entfernen
|
delete : entfernen
|
||||||
@@ -31,11 +31,13 @@ disabled : deaktiviert
|
|||||||
EAST : Osten
|
EAST : Osten
|
||||||
editable train properties : veränderliche Zug-Eigenschaften
|
editable train properties : veränderliche Zug-Eigenschaften
|
||||||
Emergency : Notfall
|
Emergency : Notfall
|
||||||
|
Firing {} : starte {}
|
||||||
FinishRoute : Route abschließen
|
FinishRoute : Route abschließen
|
||||||
FreeStartBlock : Start-Block freigeben
|
FreeStartBlock : Start-Block freigeben
|
||||||
Hardware settings : Hardware-Einstellungen
|
Hardware settings : Hardware-Einstellungen
|
||||||
Height : Höhe
|
Height : Höhe
|
||||||
Help : Hilfe
|
Help : Hilfe
|
||||||
|
if ({})\: {} : falls ({}): {}
|
||||||
inverted : invertiert
|
inverted : invertiert
|
||||||
learn : lernen
|
learn : lernen
|
||||||
LEFT : links
|
LEFT : links
|
||||||
@@ -78,6 +80,7 @@ Select relay\: : Relais auswählen:
|
|||||||
SetRelay : Relais schalten
|
SetRelay : Relais schalten
|
||||||
SetSignalsToStop : Signale auf Halt stellen
|
SetSignalsToStop : Signale auf Halt stellen
|
||||||
SetSpeed : Geschwindigkeit ändern
|
SetSpeed : Geschwindigkeit ändern
|
||||||
|
Set {} to {} : {} auf {} setzen
|
||||||
Set speed to : Geschwindigkeit setzen
|
Set speed to : Geschwindigkeit setzen
|
||||||
Setup actions : Aktivierungs-Aktionen
|
Setup actions : Aktivierungs-Aktionen
|
||||||
Signals : Signale
|
Signals : Signale
|
||||||
@@ -100,12 +103,16 @@ Trains\: : Züge:
|
|||||||
TrainHasTag : Zug mit Tag
|
TrainHasTag : Zug mit Tag
|
||||||
TrainLength : Zuglänge
|
TrainLength : Zuglänge
|
||||||
TrainSelect : Zug-Auswahl
|
TrainSelect : Zug-Auswahl
|
||||||
|
Trigger {} : {} betätigen
|
||||||
TriggerContact : Kontakt auslösen
|
TriggerContact : Kontakt auslösen
|
||||||
|
Turn : Richtung wechseln
|
||||||
Turn allowed : Wenden erlaubt
|
Turn allowed : Wenden erlaubt
|
||||||
|
{} turned. : {} gewendet.
|
||||||
Turnouts : Weichen
|
Turnouts : Weichen
|
||||||
TurnTrain : Fahrtrichtung umkehren
|
TurnTrain : Fahrtrichtung umkehren
|
||||||
Unknown action\: {} : Unbekannte Aktion: {}
|
Unknown action\: {} : Unbekannte Aktion: {}
|
||||||
unset : ungesetzt
|
unset : ungesetzt
|
||||||
|
Wait {} ms, then\: {} : {} ms warten, dann: {}
|
||||||
Was not able to assign {} to {}! : Konnte {} nicht an {} zuweisen!
|
Was not able to assign {} to {}! : Konnte {} nicht an {} zuweisen!
|
||||||
Was not able to lock {} : Konnte {} nicht reservieren
|
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 signals! : Konnte nicht alle Signale stellen!
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ import de.srsoftware.web4rail.tiles.TurnoutRW;
|
|||||||
* @author Stephan Richter, SRSoftware
|
* @author Stephan Richter, SRSoftware
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Plan implements Constants{
|
public class Plan extends BaseClass{
|
||||||
/**
|
/**
|
||||||
* The four directions Trains can be within blocks
|
* The four directions Trains can be within blocks
|
||||||
*/
|
*/
|
||||||
@@ -240,7 +240,6 @@ public class Plan implements Constants{
|
|||||||
for (Block block : blocks) {
|
for (Block block : blocks) {
|
||||||
for (Connector con : block.startPoints()) routes.addAll(follow(new Route().begin(block,con.from.inverse()),con));
|
for (Connector con : block.startPoints()) routes.addAll(follow(new Route().begin(block,con.from.inverse()),con));
|
||||||
}
|
}
|
||||||
this.routes.clear();
|
|
||||||
for (Tile tile : tiles.values()) tile.routes().clear();
|
for (Tile tile : tiles.values()) tile.routes().clear();
|
||||||
for (Route route : routes) {
|
for (Route route : routes) {
|
||||||
route.complete();
|
route.complete();
|
||||||
@@ -571,13 +570,16 @@ public class Plan implements Constants{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* adds a new route to the plan
|
* adds a new route to the plan
|
||||||
* @param route
|
* @param newRoute
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Route registerRoute(Route route) {
|
Route registerRoute(Route newRoute) {
|
||||||
for (Tile tile: route.path()) tile.add(route);
|
for (Tile tile: newRoute.path()) tile.add(newRoute);
|
||||||
routes.put(route.id(), route);
|
int routeId = newRoute.id();
|
||||||
return route;
|
Route existingRoute = routes.get(routeId);
|
||||||
|
if (isSet(existingRoute)) newRoute.addActionsFrom(existingRoute);
|
||||||
|
routes.put(routeId, newRoute);
|
||||||
|
return newRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -668,10 +670,8 @@ public class Plan implements Constants{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sensor(int addr, boolean active) {
|
public void sensor(int addr, boolean active) {
|
||||||
LOG.debug("contact({},{})",addr,active);
|
|
||||||
Contact contact = Contact.get(addr);
|
Contact contact = Contact.get(addr);
|
||||||
LOG.debug("contact: {}",contact);
|
LOG.debug("contact: {}",contact);
|
||||||
LOG.debug("learning: {}",learningContact);
|
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
contact.activate(active);
|
contact.activate(active);
|
||||||
} else {
|
} else {
|
||||||
@@ -683,7 +683,6 @@ public class Plan implements Constants{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shows the properties of an entity specified in the params.context value
|
* shows the properties of an entity specified in the params.context value
|
||||||
* @param params
|
* @param params
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -79,6 +80,7 @@ public class Route extends BaseClass{
|
|||||||
private ActionList setupActions = new ActionList();
|
private ActionList setupActions = new ActionList();
|
||||||
private Block startBlock = null;
|
private Block startBlock = null;
|
||||||
public Direction startDirection;
|
public Direction startDirection;
|
||||||
|
private HashSet<Contact> triggeredContacts = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* process commands from the client
|
* process commands from the client
|
||||||
@@ -147,6 +149,20 @@ public class Route extends BaseClass{
|
|||||||
actions.add(action);
|
actions.add(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addActionsFrom(Route existingRoute) {
|
||||||
|
LOG.debug("addActionsFrom({})",existingRoute);
|
||||||
|
setupActions.addActionsFrom(existingRoute.setupActions);
|
||||||
|
for (Entry<String, ActionList> entry : triggers.entrySet()) {
|
||||||
|
String trigger = entry.getKey();
|
||||||
|
ActionList existingActionList = existingRoute.triggers.get(trigger);
|
||||||
|
if (isSet(existingActionList)) {
|
||||||
|
LOG.debug("found action list for {} on existing route {}: {}",trigger,existingRoute,existingActionList);
|
||||||
|
ActionList newActionList = entry.getValue();
|
||||||
|
newActionList.addActionsFrom(existingActionList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void addBasicPropertiesTo(Window win) {
|
private void addBasicPropertiesTo(Window win) {
|
||||||
if (isSet(train)) link("span",Map.of(REALM,REALM_TRAIN,ID,train.id,ACTION,ACTION_PROPS),t("Train: {}",train)).addTo(win);
|
if (isSet(train)) link("span",Map.of(REALM,REALM_TRAIN,ID,train.id,ACTION,ACTION_PROPS),t("Train: {}",train)).addTo(win);
|
||||||
new Tag("h4").content(t("Origin and destination")).addTo(win);
|
new Tag("h4").content(t("Origin and destination")).addTo(win);
|
||||||
@@ -298,8 +314,10 @@ public class Route extends BaseClass{
|
|||||||
* @param trainHead
|
* @param trainHead
|
||||||
*/
|
*/
|
||||||
public void contact(Contact contact) {
|
public void contact(Contact contact) {
|
||||||
traceTrainFrom(contact);
|
if (triggeredContacts.contains(contact)) return; // don't trigger contact a second time
|
||||||
|
triggeredContacts.add(contact);
|
||||||
LOG.debug("{} on {} activated {}.",train,this,contact);
|
LOG.debug("{} on {} activated {}.",train,this,contact);
|
||||||
|
traceTrainFrom(contact);
|
||||||
ActionList actions = triggers.get(contact.trigger());
|
ActionList actions = triggers.get(contact.trigger());
|
||||||
if (isNull(actions)) return;
|
if (isNull(actions)) return;
|
||||||
Context context = new Context(contact);
|
Context context = new Context(contact);
|
||||||
@@ -314,6 +332,10 @@ public class Route extends BaseClass{
|
|||||||
return REALM_ROUTE+":"+id();
|
return REALM_ROUTE+":"+id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDisabled() {
|
||||||
|
return disabled;
|
||||||
|
}
|
||||||
|
|
||||||
private Object dropCodition(HashMap<String, String> params) {
|
private Object dropCodition(HashMap<String, String> params) {
|
||||||
String condId = params.get(REALM_CONDITION);
|
String condId = params.get(REALM_CONDITION);
|
||||||
if (isSet(condId)) {
|
if (isSet(condId)) {
|
||||||
@@ -344,7 +366,7 @@ public class Route extends BaseClass{
|
|||||||
train.heading(endDirection.inverse());
|
train.heading(endDirection.inverse());
|
||||||
if (train.route == this) train.route = null;
|
if (train.route == this) train.route = null;
|
||||||
train = null;
|
train = null;
|
||||||
|
triggeredContacts.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean fireSetupActions(Context context) {
|
public boolean fireSetupActions(Context context) {
|
||||||
@@ -522,7 +544,7 @@ public class Route extends BaseClass{
|
|||||||
name = generateName();
|
name = generateName();
|
||||||
name(name);
|
name(name);
|
||||||
}
|
}
|
||||||
return name + (disabled?" ["+t("disabled")+"]" : "");
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void name(String name) {
|
public void name(String name) {
|
||||||
@@ -559,6 +581,7 @@ public class Route extends BaseClass{
|
|||||||
train.heading(startDirection);
|
train.heading(startDirection);
|
||||||
if (train.route == this) train.route = null;
|
if (train.route == this) train.route = null;
|
||||||
}
|
}
|
||||||
|
triggeredContacts.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ public abstract class Action extends BaseClass {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean equals(Action other) {
|
||||||
|
return this.toString().equals(other.toString());
|
||||||
|
}
|
||||||
|
|
||||||
public abstract boolean fire(Context context) throws IOException;
|
public abstract boolean fire(Context context) throws IOException;
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,29 @@ public class ActionList extends Vector<Action> implements Constants{
|
|||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addActionsFrom(ActionList other) {
|
||||||
|
for (Action otherAction : other) {
|
||||||
|
LOG.debug("old action: {}",otherAction);
|
||||||
|
boolean exists = false;
|
||||||
|
int len = this.size();
|
||||||
|
for (int i=0; i<len; i++) {
|
||||||
|
Action thisAction = this.get(i);
|
||||||
|
LOG.debug("→ {} ?",thisAction);
|
||||||
|
if (thisAction.equals(otherAction)) {
|
||||||
|
LOG.debug("Action already existing!");
|
||||||
|
exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (exists) {
|
||||||
|
LOG.debug("action not added.");
|
||||||
|
} else {
|
||||||
|
this.add(otherAction);
|
||||||
|
LOG.debug("action added.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void addTo(Tag link, String context) {
|
public void addTo(Tag link, String context) {
|
||||||
Map<String, Object> props = new HashMap<String, Object>(Map.of(
|
Map<String, Object> props = new HashMap<String, Object>(Map.of(
|
||||||
REALM,REALM_ACTIONS,
|
REALM,REALM_ACTIONS,
|
||||||
@@ -121,7 +144,7 @@ public class ActionList extends Vector<Action> implements Constants{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean fire(Context context) {
|
public boolean fire(Context context) {
|
||||||
LOG.debug("Firing {}",this);
|
LOG.debug(t("Firing {}"),this);
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
for (Action action : this) {
|
for (Action action : this) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class ConditionalAction extends Action {
|
|||||||
if (i>0) sb.append(t(" or "));
|
if (i>0) sb.append(t(" or "));
|
||||||
sb.append(conditions.get(i).toString());
|
sb.append(conditions.get(i).toString());
|
||||||
}
|
}
|
||||||
return t("if ({}):",sb);
|
return t("if ({}): {}",sb,actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class DelayedAction extends Action {
|
|||||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||||
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||||
|
|
||||||
new Input(DELAY,delay).numeric().addTo(new Label(t("Delay")+NBSP)).content(" ms").addTo(form);
|
new Input(DELAY,delay).numeric().addTo(new Label(t("Delay")+NBSP)).content(NBSP+"ms").addTo(form);
|
||||||
return new Button(t("Apply"),form).addTo(form).addTo(fieldset);
|
return new Button(t("Apply"),form).addTo(form).addTo(fieldset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,8 +59,6 @@ public class DelayedAction extends Action {
|
|||||||
}.start();
|
}.start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
@@ -87,7 +85,7 @@ public class DelayedAction extends Action {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return t("Wait {} ms, then:",delay);
|
return t("Wait {} ms, then: {}",delay,actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class SetRelay extends Action {
|
|||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (isNull(relay)) return "["+t("click here to setup relay")+"]";
|
if (isNull(relay)) return "["+t("click here to setup relay")+"]";
|
||||||
return t("Set "+relay+" to "+(state?relay.stateLabelA:relay.stateLabelB));
|
return t("Set {} to {}",relay,state?relay.stateLabelA:relay.stateLabelB);
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Tag link(String tagClass) {
|
public Tag link(String tagClass) {
|
||||||
return link(tagClass, Map.of(REALM, REALM_TRAIN,ID,id,ACTION,ACTION_PROPS),name());
|
return link(tagClass, Map.of(REALM, REALM_TRAIN,ID,id,ACTION,ACTION_PROPS),name()+NBSP);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TreeSet<Train> list() {
|
public static TreeSet<Train> list() {
|
||||||
@@ -539,7 +539,6 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSpeed(int v) {
|
public void setSpeed(int v) {
|
||||||
LOG.debug("Setting speed to {} kmh.",v);
|
|
||||||
for (Locomotive loco : locos) loco.setSpeed(v);
|
for (Locomotive loco : locos) loco.setSpeed(v);
|
||||||
this.speed = v;
|
this.speed = v;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ public abstract class Tile extends BaseClass{
|
|||||||
Tag routeList = new Tag("ol");
|
Tag routeList = new Tag("ol");
|
||||||
for (Route route : routes) {
|
for (Route route : routes) {
|
||||||
String json = new JSONObject(Map.of(REALM,ROUTE,ID,route.id(),ACTION,ACTION_PROPS,CONTEXT,REALM_PLAN+":"+id())).toString().replace("\"", "'");
|
String json = new JSONObject(Map.of(REALM,ROUTE,ID,route.id(),ACTION,ACTION_PROPS,CONTEXT,REALM_PLAN+":"+id())).toString().replace("\"", "'");
|
||||||
Tag li = new Tag("span").attr("onclick","return request("+json+");").content(route.name()+NBSP).addTo(new Tag("li").clazz("link"));
|
Tag li = new Tag("span").attr("onclick","return request("+json+");").content(route.name()+(route.isDisabled()?" ["+t("disabled")+"]" : "")+NBSP).addTo(new Tag("li").clazz("link"));
|
||||||
Map<String, Object> params = Map.of(REALM,REALM_ROUTE,ID,route.id(),ACTION,ACTION_DROP,Tile.class.getSimpleName(),id());
|
Map<String, Object> params = Map.of(REALM,REALM_ROUTE,ID,route.id(),ACTION,ACTION_DROP,Tile.class.getSimpleName(),id());
|
||||||
new Button(t("delete route"),params).addTo(li);
|
new Button(t("delete route"),params).addTo(li);
|
||||||
li.addTo(routeList);
|
li.addTo(routeList);
|
||||||
|
|||||||
Reference in New Issue
Block a user