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>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>0.10.7</version>
|
||||
<version>0.10.8s</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -21,7 +21,7 @@ Control unit : Zentrale
|
||||
Current location\: : Aktueller Ort:
|
||||
Actions and contacts : Aktionen und Kontakte
|
||||
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
|
||||
DelayedAction : verzögerte Aktion
|
||||
delete : entfernen
|
||||
@@ -31,11 +31,13 @@ disabled : deaktiviert
|
||||
EAST : Osten
|
||||
editable train properties : veränderliche Zug-Eigenschaften
|
||||
Emergency : Notfall
|
||||
Firing {} : starte {}
|
||||
FinishRoute : Route abschließen
|
||||
FreeStartBlock : Start-Block freigeben
|
||||
Hardware settings : Hardware-Einstellungen
|
||||
Height : Höhe
|
||||
Help : Hilfe
|
||||
if ({})\: {} : falls ({}): {}
|
||||
inverted : invertiert
|
||||
learn : lernen
|
||||
LEFT : links
|
||||
@@ -78,6 +80,7 @@ Select relay\: : Relais auswählen:
|
||||
SetRelay : Relais schalten
|
||||
SetSignalsToStop : Signale auf Halt stellen
|
||||
SetSpeed : Geschwindigkeit ändern
|
||||
Set {} to {} : {} auf {} setzen
|
||||
Set speed to : Geschwindigkeit setzen
|
||||
Setup actions : Aktivierungs-Aktionen
|
||||
Signals : Signale
|
||||
@@ -100,12 +103,16 @@ Trains\: : Züge:
|
||||
TrainHasTag : Zug mit Tag
|
||||
TrainLength : Zuglänge
|
||||
TrainSelect : Zug-Auswahl
|
||||
Trigger {} : {} betätigen
|
||||
TriggerContact : Kontakt auslösen
|
||||
Turn : Richtung wechseln
|
||||
Turn allowed : Wenden erlaubt
|
||||
{} turned. : {} gewendet.
|
||||
Turnouts : Weichen
|
||||
TurnTrain : Fahrtrichtung umkehren
|
||||
Unknown action\: {} : Unbekannte Aktion: {}
|
||||
unset : ungesetzt
|
||||
Wait {} ms, then\: {} : {} ms warten, dann: {}
|
||||
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!
|
||||
|
||||
@@ -70,7 +70,7 @@ import de.srsoftware.web4rail.tiles.TurnoutRW;
|
||||
* @author Stephan Richter, SRSoftware
|
||||
*
|
||||
*/
|
||||
public class Plan implements Constants{
|
||||
public class Plan extends BaseClass{
|
||||
/**
|
||||
* The four directions Trains can be within blocks
|
||||
*/
|
||||
@@ -240,7 +240,6 @@ public class Plan implements Constants{
|
||||
for (Block block : blocks) {
|
||||
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 (Route route : routes) {
|
||||
route.complete();
|
||||
@@ -571,13 +570,16 @@ public class Plan implements Constants{
|
||||
|
||||
/**
|
||||
* adds a new route to the plan
|
||||
* @param route
|
||||
* @param newRoute
|
||||
* @return
|
||||
*/
|
||||
Route registerRoute(Route route) {
|
||||
for (Tile tile: route.path()) tile.add(route);
|
||||
routes.put(route.id(), route);
|
||||
return route;
|
||||
Route registerRoute(Route newRoute) {
|
||||
for (Tile tile: newRoute.path()) tile.add(newRoute);
|
||||
int routeId = newRoute.id();
|
||||
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) {
|
||||
LOG.debug("contact({},{})",addr,active);
|
||||
Contact contact = Contact.get(addr);
|
||||
LOG.debug("contact: {}",contact);
|
||||
LOG.debug("learning: {}",learningContact);
|
||||
if (contact != null) {
|
||||
contact.activate(active);
|
||||
} else {
|
||||
@@ -683,7 +683,6 @@ public class Plan implements Constants{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* shows the properties of an entity specified in the params.context value
|
||||
* @param params
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -79,6 +80,7 @@ public class Route extends BaseClass{
|
||||
private ActionList setupActions = new ActionList();
|
||||
private Block startBlock = null;
|
||||
public Direction startDirection;
|
||||
private HashSet<Contact> triggeredContacts = new HashSet<>();
|
||||
|
||||
/**
|
||||
* process commands from the client
|
||||
@@ -147,6 +149,20 @@ public class Route extends BaseClass{
|
||||
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) {
|
||||
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);
|
||||
@@ -298,8 +314,10 @@ public class Route extends BaseClass{
|
||||
* @param trainHead
|
||||
*/
|
||||
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);
|
||||
traceTrainFrom(contact);
|
||||
ActionList actions = triggers.get(contact.trigger());
|
||||
if (isNull(actions)) return;
|
||||
Context context = new Context(contact);
|
||||
@@ -314,6 +332,10 @@ public class Route extends BaseClass{
|
||||
return REALM_ROUTE+":"+id();
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
private Object dropCodition(HashMap<String, String> params) {
|
||||
String condId = params.get(REALM_CONDITION);
|
||||
if (isSet(condId)) {
|
||||
@@ -344,7 +366,7 @@ public class Route extends BaseClass{
|
||||
train.heading(endDirection.inverse());
|
||||
if (train.route == this) train.route = null;
|
||||
train = null;
|
||||
|
||||
triggeredContacts.clear();
|
||||
}
|
||||
|
||||
public boolean fireSetupActions(Context context) {
|
||||
@@ -522,7 +544,7 @@ public class Route extends BaseClass{
|
||||
name = generateName();
|
||||
name(name);
|
||||
}
|
||||
return name + (disabled?" ["+t("disabled")+"]" : "");
|
||||
return name;
|
||||
}
|
||||
|
||||
public void name(String name) {
|
||||
@@ -559,6 +581,7 @@ public class Route extends BaseClass{
|
||||
train.heading(startDirection);
|
||||
if (train.route == this) train.route = null;
|
||||
}
|
||||
triggeredContacts.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,10 @@ public abstract class Action extends BaseClass {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean equals(Action other) {
|
||||
return this.toString().equals(other.toString());
|
||||
}
|
||||
|
||||
public abstract boolean fire(Context context) throws IOException;
|
||||
|
||||
public static Action get(int actionId) {
|
||||
|
||||
@@ -74,6 +74,29 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
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) {
|
||||
Map<String, Object> props = new HashMap<String, Object>(Map.of(
|
||||
REALM,REALM_ACTIONS,
|
||||
@@ -121,7 +144,7 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
}
|
||||
|
||||
public boolean fire(Context context) {
|
||||
LOG.debug("Firing {}",this);
|
||||
LOG.debug(t("Firing {}"),this);
|
||||
boolean success = true;
|
||||
for (Action action : this) {
|
||||
try {
|
||||
|
||||
@@ -102,7 +102,7 @@ public class ConditionalAction extends Action {
|
||||
if (i>0) sb.append(t(" or "));
|
||||
sb.append(conditions.get(i).toString());
|
||||
}
|
||||
return t("if ({}):",sb);
|
||||
return t("if ({}): {}",sb,actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,7 +41,7 @@ public class DelayedAction extends Action {
|
||||
new Input(ACTION,ACTION_UPDATE).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);
|
||||
}
|
||||
|
||||
@@ -60,8 +60,6 @@ public class DelayedAction extends Action {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
JSONObject json = super.json();
|
||||
@@ -87,7 +85,7 @@ public class DelayedAction extends Action {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return t("Wait {} ms, then:",delay);
|
||||
return t("Wait {} ms, then: {}",delay,actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -78,7 +78,7 @@ public class SetRelay extends Action {
|
||||
|
||||
public String toString() {
|
||||
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
|
||||
|
||||
@@ -335,7 +335,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -539,7 +539,6 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
}
|
||||
|
||||
public void setSpeed(int v) {
|
||||
LOG.debug("Setting speed to {} kmh.",v);
|
||||
for (Locomotive loco : locos) loco.setSpeed(v);
|
||||
this.speed = v;
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ public abstract class Tile extends BaseClass{
|
||||
Tag routeList = new Tag("ol");
|
||||
for (Route route : routes) {
|
||||
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());
|
||||
new Button(t("delete route"),params).addTo(li);
|
||||
li.addTo(routeList);
|
||||
|
||||
Reference in New Issue
Block a user