|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|