preparing wait times for use in blocks
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.14</version>
|
<version>0.10.15</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>
|
||||||
|
|||||||
@@ -251,3 +251,12 @@ svg.disabled rect{
|
|||||||
stroke-width:5;
|
stroke-width:5;
|
||||||
stroke: red;
|
stroke: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#train-wait-form input{
|
||||||
|
text-align: right;
|
||||||
|
width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#train-wait-form td{
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
@@ -71,12 +71,25 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
private Vector<Locomotive> locos = new Vector<Locomotive>();
|
private Vector<Locomotive> locos = new Vector<Locomotive>();
|
||||||
|
|
||||||
private static final String TAGS = "tags";
|
private static final String TAGS = "tags";
|
||||||
|
private static final String WAIT_TIMES = "wait_times";
|
||||||
|
private static final String MAX = "max";
|
||||||
|
private static final String MIN = "min";
|
||||||
|
|
||||||
private HashSet<String> tags = new HashSet<String>();
|
private HashSet<String> tags = new HashSet<String>();
|
||||||
|
private HashMap<String, WaitTime> waitTimes = new HashMap<String, WaitTime>();
|
||||||
|
|
||||||
|
|
||||||
private Block block = null;
|
private Block block = null;
|
||||||
LinkedList<Tile> trace = new LinkedList<Tile>();
|
LinkedList<Tile> trace = new LinkedList<Tile>();
|
||||||
|
|
||||||
|
public class WaitTime{
|
||||||
|
public int min =0,max=10000;
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return min+"..."+max+" s";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class Autopilot extends Thread{
|
private class Autopilot extends Thread{
|
||||||
boolean stop = false;
|
boolean stop = false;
|
||||||
|
|
||||||
@@ -327,6 +340,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
json.put(TRACE, tileIds);
|
json.put(TRACE, tileIds);
|
||||||
|
|
||||||
if (!tags.isEmpty()) json.put(TAGS, tags);
|
if (!tags.isEmpty()) json.put(TAGS, tags);
|
||||||
|
JSONObject jWaitTimes = new JSONObject();
|
||||||
|
for (Entry<String, WaitTime> entry: waitTimes.entrySet()) {
|
||||||
|
jWaitTimes.put(entry.getKey(), Map.of(MIN,entry.getValue().min,MAX,entry.getValue().max));
|
||||||
|
}
|
||||||
|
json.put(WAIT_TIMES, jWaitTimes);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,7 +388,14 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if (json.has(BLOCK)) block = (Block) plan.get(json.getString(BLOCK), false).set(this); // do not move this up! during set, other fields will be referenced!
|
if (json.has(BLOCK)) block = (Block) plan.get(json.getString(BLOCK), false).set(this); // do not move this up! during set, other fields will be referenced!
|
||||||
for (Object id : json.getJSONArray(CARS)) add(Car.get(id));
|
for (Object id : json.getJSONArray(CARS)) add(Car.get(id));
|
||||||
for (Object id : json.getJSONArray(LOCOS)) add((Locomotive) Car.get(id));
|
for (Object id : json.getJSONArray(LOCOS)) add((Locomotive) Car.get(id));
|
||||||
|
if (json.has(WAIT_TIMES)) {
|
||||||
|
JSONObject jWaitTimes = json.getJSONObject(WAIT_TIMES);
|
||||||
|
for (String key : jWaitTimes.keySet()) {
|
||||||
|
JSONObject wt = jWaitTimes.getJSONObject(key);
|
||||||
|
setWaitTime(key, wt.getInt(MIN), true);
|
||||||
|
setWaitTime(key, wt.getInt(MAX), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,6 +576,22 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
this.speed = v;
|
this.speed = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWaitTime(String key,int time, boolean min) {
|
||||||
|
WaitTime wt = waitTime(key);
|
||||||
|
if (time < 0) time = 0;
|
||||||
|
if (min) {
|
||||||
|
wt.min = time;
|
||||||
|
if (wt.max < time) wt.max = time;
|
||||||
|
} else {
|
||||||
|
wt.max = time;
|
||||||
|
if (wt.min > time) wt.min = time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWaitTime(Block block, Direction dir, int time, boolean min) {
|
||||||
|
setWaitTime(block.id()+":"+dir, time, min);
|
||||||
|
}
|
||||||
|
|
||||||
public void showTrace() {
|
public void showTrace() {
|
||||||
int remainingLength = length();
|
int remainingLength = length();
|
||||||
if (remainingLength<1) remainingLength=1;
|
if (remainingLength<1) remainingLength=1;
|
||||||
@@ -643,11 +684,21 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void removeFromTrace(Tile tile) {
|
public void removeFromTrace(Tile tile) {
|
||||||
trace.remove(tile);
|
trace.remove(tile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WaitTime waitTime(String key) {
|
||||||
|
WaitTime wt = waitTimes.get(key);
|
||||||
|
if (wt == null) {
|
||||||
|
wt = new WaitTime();
|
||||||
|
waitTimes.put(key, wt);
|
||||||
|
}
|
||||||
|
return wt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WaitTime waitTime(Block block, Direction dir) {
|
||||||
|
return waitTime(block.id()+":"+dir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,17 @@ import java.io.IOException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.Connector;
|
import de.srsoftware.web4rail.Connector;
|
||||||
|
import de.srsoftware.web4rail.Plan.Direction;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
import de.srsoftware.web4rail.moving.Train;
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
|
import de.srsoftware.web4rail.moving.Train.WaitTime;
|
||||||
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
import de.srsoftware.web4rail.tags.Checkbox;
|
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;
|
||||||
@@ -34,6 +39,9 @@ public abstract class Block extends StretchableTile{
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract Direction directionA();
|
||||||
|
public abstract Direction directionB();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
JSONObject json = super.json();
|
JSONObject json = super.json();
|
||||||
@@ -65,6 +73,52 @@ public abstract class Block extends StretchableTile{
|
|||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Window propMenu() {
|
||||||
|
Window win = super.propMenu();
|
||||||
|
Form form = new Form("train-wait-form");
|
||||||
|
new Tag("h4").content(t("Stop settings")).addTo(win);
|
||||||
|
new Input(REALM,REALM_PLAN).hideIn(form);
|
||||||
|
new Input(ID,id()).hideIn(form);
|
||||||
|
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||||
|
|
||||||
|
Tag table = new Tag("table");
|
||||||
|
Tag row = new Tag("tr");
|
||||||
|
new Tag("td").content(t("Direction")).addTo(row);
|
||||||
|
new Tag("th").attr("colspan", 2).content(directionA().toString()).addTo(row);
|
||||||
|
new Tag("th").attr("colspan", 2).content(directionB().toString()).addTo(row);
|
||||||
|
|
||||||
|
row.addTo(table);
|
||||||
|
|
||||||
|
row = new Tag("tr");
|
||||||
|
new Tag("th").content(t("Train")).addTo(row);
|
||||||
|
new Tag("th").content(t("min")).addTo(row);
|
||||||
|
new Tag("th").content(t("max")).addTo(row);
|
||||||
|
new Tag("th").content(t("min")).addTo(row);
|
||||||
|
new Tag("th").content(t("max")).addTo(row);
|
||||||
|
row.addTo(table);
|
||||||
|
|
||||||
|
for (Train train : Train.list()) {
|
||||||
|
row = new Tag("tr");
|
||||||
|
new Tag("td").content(train.name()).addTo(row);
|
||||||
|
Direction a = directionA();
|
||||||
|
WaitTime wtA = train.waitTime(this, a);
|
||||||
|
Direction b = directionB();
|
||||||
|
WaitTime wtB = train.waitTime(this, b);
|
||||||
|
new Input("train."+train.id+"."+directionA()+".min",wtA.min).numeric().addTo(new Tag("td")).addTo(row);
|
||||||
|
new Input("train."+train.id+"."+directionA()+".max",wtA.max).numeric().addTo(new Tag("td")).addTo(row);
|
||||||
|
new Input("train."+train.id+"."+directionB()+".min",wtB.min).numeric().addTo(new Tag("td")).addTo(row);
|
||||||
|
new Input("train."+train.id+"."+directionB()+".max",wtB.max).numeric().addTo(new Tag("td")).addTo(row);
|
||||||
|
row.addTo(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
table.addTo(form);
|
||||||
|
|
||||||
|
new Button(t("Apply")).addTo(form).addTo(win);
|
||||||
|
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract List<Connector> startPoints();
|
public abstract List<Connector> startPoints();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -107,6 +161,26 @@ public abstract class Block extends StretchableTile{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
turnAllowed = params.containsKey(ALLOW_TURN) && params.get(ALLOW_TURN).equals("on");
|
turnAllowed = params.containsKey(ALLOW_TURN) && params.get(ALLOW_TURN).equals("on");
|
||||||
|
|
||||||
|
for (Entry<String, String> entry : params.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
if (key.startsWith("train.")) {
|
||||||
|
String[] parts = key.split("\\.");
|
||||||
|
int trainId = Integer.parseInt(parts[1]);
|
||||||
|
Train t = Train.get(trainId);
|
||||||
|
if (t == null) continue;
|
||||||
|
|
||||||
|
Direction dir = Direction.valueOf(parts[2]);
|
||||||
|
boolean min = parts[3].equals("min");
|
||||||
|
int time = Integer.parseInt(entry.getValue());
|
||||||
|
|
||||||
|
t.setWaitTime(this,dir,time,min);
|
||||||
|
|
||||||
|
LOG.debug("{} / {} : {}",t,dir,t.waitTime(this, dir));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return super.update(params);
|
return super.update(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,16 @@ public class BlockH extends Block{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction directionA() {
|
||||||
|
return Direction.WEST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction directionB() {
|
||||||
|
return Direction.EAST;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int width() {
|
public int width() {
|
||||||
return stretch;
|
return stretch;
|
||||||
|
|||||||
@@ -24,6 +24,16 @@ public class BlockV extends Block{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction directionA() {
|
||||||
|
return Direction.NORTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction directionB() {
|
||||||
|
return Direction.SOUTH;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int height() {
|
public int height() {
|
||||||
return stretch;
|
return stretch;
|
||||||
|
|||||||
Reference in New Issue
Block a user